![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Merge lines into one | anypager | Shell Programming and Scripting | 7 | 05-22-2008 03:20 PM |
| retrieved multiple lines on multiple places in a file | dala | Shell Programming and Scripting | 8 | 03-14-2008 03:28 PM |
| merge 2 files (without repeating any lines) | bluemoon1 | Shell Programming and Scripting | 9 | 10-25-2007 10:31 PM |
| merge multiple lines from flat file | hnhegde | Shell Programming and Scripting | 4 | 12-05-2006 07:13 PM |
| Merge wrapped lines | braindrain | Shell Programming and Scripting | 1 | 07-25-2005 07:03 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Use sed to merge multiple lines
Hi all:
I have a file in which the contents are as following: ... This is a test ONE TWO Hello, world! XXX YYY CCC test again three, four five six seven world AAA BBB QQQ test eight, nine world FFF EEE KKK ... I want to use sed to merge all lines between a line that contains a word 'test' and a line that contains a word 'world' into one line, and ignore other lines. In other words, I want a result as following: This is a test ONE TWO Hello, world! test again three, four five six seven world test eight, nine world Any help is appreciated. Thanks in advance for your help! Sincerely, Susan |
|
||||
|
Quote:
Code:
awk '/test/,/world/{ if($0~/world/) ORS="\n"; else ORS=" "; print}' filename
This is a test ONE TWO Hello, world! test again three, four five six seven world test eight, nine world |
|
||||
|
Thanks to both System Shock and vish indian! It seems there is no easy way for sed to do it. I have to use awk, perl, or something else ...
|
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|