String: Grep / SED for multy line search


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting String: Grep / SED for multy line search
# 1  
Old 02-22-2011
Question String: Grep / SED for multy line search

Hi,
At first I want to please you to provide the solution with grep/sed if possible. Smilie


File looks like:
Quote:
/folder_start/folder_A2/file_A.typea
version: /main/another_folder/1
some,.,?=)(!"/()&%§(/& other information.... do not care -.,?============================
/folder_start/folder_B2/file_B.typeb
version: /main/folder/6
some,.,?=)(!"/()&%§(/& other information.... do not care -.,?============================
wished result:
Quote:
/folder_start/folder_A2/file_A.typea@@/main/another_folder/1
/folder_start/folder_B2/file_B.typeb@@/main/folder/6
so I want in a new file
BLUE@@RED

string from first line like:
Code:
grep "/folder_start" cs_src > tmp1



string from second line:
Code:
grep "/main" cs_src | cut -d " " -f6 > tmp2



logic: RESULT = string1 + @@ + string2
note:
one line command for console would be great - please give solution with grep&cut / sed

couldn't combine the outputs with "@@" and print in new file - maybe use "cat"?
thanks Smilie
# 2  
Old 02-22-2011
This can be done with just a sed command:
Code:
$ cat ifile
/folder_start/folder_A2/file_A.typea
version: /main/another_folder/1
some,.,?=)(!"/()&%§(/& other information.... do not care -.,?============================
/folder_start/folder_B2/file_B.typeb
version: /main/folder/6
some,.,?=)(!"/()&%§(/& other information.... do not care -.,?============================

$
$
$
$ sed -n '/folder_start/{N;s/\nversion: /@@/p;}' ifile
/folder_start/folder_A2/file_A.typea@@/main/another_folder/1
/folder_start/folder_B2/file_B.typeb@@/main/folder/6
$

# 3  
Old 02-22-2011
Code:
sed -n '/folder_start/{N;s/\nversion: /@@/p;}' ifile

did not work for me...
edit: note: No error but also no output (right dir and right file choosen)

could you please explain me the command step by step? I'm not that familiar with these
-n,
{},
N,
p

thanks

Last edited by unknown7; 02-22-2011 at 01:47 PM.. Reason: add note
# 4  
Old 02-22-2011
What system are you using? It works for me on Solaris and Linux.

-n means do not print lines unless instructed to.
{} groups commands together
N reads another line
p prints
This User Gave Thanks to Perderabo For This Post:
# 5  
Old 02-22-2011
works well...
using SUN OS

did smth. wrong... thanks - exactly what i searched for... a one line sed command!
# 6  
Old 03-16-2011
Power multy line remove newline and last slash in a line

Hi again,

how can i remove newlines and lst slash?

Examplecode:
Quote:
abc/de/fg/
12/3/4/5/67/
morestuff/
i want to remove the last slash in a line and the newlines

Quote:
expected result:
abc/de/fg12/3/4/5/67morestuff
# 7  
Old 03-16-2011
Try this,
Code:
sed 's/\/$//g' inputfile | paste -s -d ""

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to use a grep search to search for a specific string within multiple directories?

Lets say I have a massive directory which is filled with other directories all filled with different c++ scripts and I want a listing of all the scripts that contain the string: "this string". Is there a way to use a grep search for that? I tried: grep -lr "this string" * but I do not... (3 Replies)
Discussion started by: Circuits
3 Replies

2. Shell Programming and Scripting

Grep command to search a regular expression in a line an only print the string after the match

Hello, one step in a shell script i am writing, involves Grep command to search a regular expression in a line an only print the string after the match an example line is below /logs/GRAS/LGT/applogs/lgt-2016-08-24/2016-08-24.8.log.zip:2016-08-24 19:12:48,602 ERROR... (9 Replies)
Discussion started by: Ramneekgupta91
9 Replies

3. Shell Programming and Scripting

Search string within a file and list common words from the line having the search string

Hi, Need your help for this scripting issue I have. I am not really good at this, so seeking your help. I have a file looking similar to this: Hello, i am human and name=ABCD. How are you? Hello, i am human and name=PQRS. I am good. Hello, i am human and name=ABCD. Good bye. Hello, i... (12 Replies)
Discussion started by: royzlife
12 Replies

4. Shell Programming and Scripting

Search a string in a text file and add another string at the end of line

Dear All I am having a text file which is having more than 200 lines. EX: 001010122 12000 BIB 12000 11200 1200003 001010122 2000 AND 12000 11200 1200003 001010122 12000 KVB 12000 11200 1200003 In the above file i want to search for string KVB... (5 Replies)
Discussion started by: suryanarayana
5 Replies

5. Shell Programming and Scripting

Search a string in a text file and add another string at the particular position of a line

I am having a text file which is having more than 200 lines. EX: 001010122 12000 BIB 12000 11200 1200003 001010122 2000 AND 12000 11200 1200003 001010122 12000 KVB 12000 11200 1200003 In the above file i want to search for string KVB and add/replace... (1 Reply)
Discussion started by: suryanarayana
1 Replies

6. Shell Programming and Scripting

Search several string and convert into a single line for each search string using awk command AIX?.

I need to search the file using strings "Request Type" , " Request Method" , "Response Type" and by using result set find the xml tags and convert into a single line?. below are the scenarios. Cat test Nov 10, 2012 5:17:53 AM INFO: Request Type Line 1.... (5 Replies)
Discussion started by: laknar
5 Replies

7. Shell Programming and Scripting

GREP/SED - get string in a line

Hi, I simply try to get a string in a line but I do smth. wrong. Hopfefully you can help me ;) tried smth like: ggrep -Eo " /folder1/folder2/folder3/* end" get_info_file > temp.file I played a bit around but could not specify the end string command... So this is the... (9 Replies)
Discussion started by: unknown7
9 Replies

8. Shell Programming and Scripting

How to use sed to search for string and Print previous two lines and current line

Hello, Can anybody help me to correct my sed syntax to find the string and print previous two lines and current line and next one line. i am using string as "testing" netstat -v | sed -n -e '/test/{x;2!p;g;$!N;p;D;}' -e h i am able to get the previous line current line next line but... (1 Reply)
Discussion started by: nmadhuhb
1 Replies

9. Shell Programming and Scripting

Perl: Search for string on line then search and replace text

Hi All, I have a file that I need to be able to find a pattern match on a line, search that line for a text pattern, and replace that text. An example of 4 lines in my file is: 1. MatchText_randomNumberOfText moreData ReplaceMe moreData 2. MatchText_randomNumberOfText moreData moreData... (4 Replies)
Discussion started by: Crypto
4 Replies

10. UNIX for Dummies Questions & Answers

grep a string in a line using sed

Hi, I'm trying to grep a string in a line using sed. My original data looks like this: MRTG$ grep -i "System" $file <H1>Traffic Analysis for 15 -- sERITHC3602.t-mobile.co.uk</H1> <TABLE> <TR><TD>System:</TD> <TD>sERITHC3602 in </TD></TR> <TR><TD>Maintainer:</TD> <TD></TD></TR>... (4 Replies)
Discussion started by: viadisky
4 Replies
Login or Register to Ask a Question