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
# 8  
Old 03-16-2011
Hi pravin... does not work...
what shall i use as delimiter?

tried "" and "\n"

So your command gives following error:
Code:
paste: no delimiters

and mine works with \n but i can't see any difference.... lines are still not concat. to 1 line and single string wasn't removed

Last edited by unknown7; 03-16-2011 at 11:21 AM..
# 9  
Old 03-16-2011
Lets try with:
Code:
echo "abc/de/fg/
12/3/4/5/67/
morestuff/" | sed 's/\/$//' | tr -d "\n"
abc/de/fg12/3/4/5/67morestuff

Regards
This User Gave Thanks to cgkmal For This Post:
# 10  
Old 03-17-2011
Let's try with perl.
Code:
perl -ne 'chop $_;printf $_; END {printf "\n";}' input.txt

This User Gave Thanks to pravin27 For This Post:
# 11  
Old 03-17-2011
TRY

Code:
sed 's/\/$//g' inputfile | awk '{ORS="";print}'|xargs| sed 's/\/$//g'

This User Gave Thanks to suresh.boddepu For This Post:
# 12  
Old 03-17-2011
@suresh.boddepu works well thx / for noobs like me ;-) i checked manpage:
ORS output record separator (default new-line)
@pravin27 does not remove the / at line ending - but thx for try... just need to add this removal
@cgkmal nice... can you please tell me how this command would look like with input and output file?

Thanks a lot!

---------- Post updated at 02:57 PM ---------- Previous update was at 12:06 PM ----------

This works fine:

Code:
sed 's/\/$//g' inputfile | awk '{ORS="";print}' > outputfile

# 13  
Old 03-17-2011
I don't understand the full requirements. Are we guaranteed that we have exactly 3 lines. Or are we guaranteed that we have a multiple of 3 lines and every 3 lines should be combined into a single line. Assuming one of these is true....
Code:
$
$ cat inputfile
abc/de/fg/
12/3/4/5/67/
morestuff/
zxy/xx/kk/
99/8/7/9/9999/
evenmorestuff/
$ sed -n 'N;N;s=/\n==g;s=/$==;p' inputfile
abc/de/fg12/3/4/5/67morestuff
zxy/xx/kk99/8/7/9/9999evenmorestuff
$

I cut and pasted this from a terminal window to a Solaris system where I tested it. This works on Solaris 10.
# 14  
Old 03-18-2011
Quote:
Originally Posted by unknown7
@cgkmal nice... can you please tell me how this command would look like with input and output file?
Hi unknown7,

Sure!. It would be like this:

Code:
sed 's/\/$//' inputfile | tr -d "\n" 
abc/de/fg12/3/4/5/67morestuff

or
Code:
sed 's/\/$//' inputfile | tr -d "\n" > outputfile

cat outputfile
abc/de/fg12/3/4/5/67morestuff

Best regards
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