If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > Concatenate lines with sed?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-04-05, 20:11
old_farmer old_farmer is offline
Registered User
 
Join Date: Feb 2005
Posts: 19
Concatenate lines with sed?

I am trying this to concatenate lines in a file with this command:

sed -ne '/|$/N/s/\\\n//p' test1.txt > test2.txt

but its not working.

I want to concatenate all lines that end with | between a "start_here" string and an "end_here" string.

So my file is like this:

"start_here"|
ldfjlsdffj|
93849340|
9034093|
"end_here"|
"start_here"|
ldfjlsdffj|
93849340|
9034093|
"end_here"|

...and it keeps repeating. But I want to concatenate everything between "start_here" and "end_here" to merge only the lines between and continue this throughout the file.

Any suggestions please?

Thanks a lot
Reply With Quote
  #2 (permalink)  
Old 02-04-05, 21:37
vgersh99 vgersh99 is offline
Registered User
 
Join Date: Apr 2004
Location: Boston, MA
Posts: 325
what is the desired output given this sample input?
__________________
vlad
+-----------------------+
| #include <disclaimer.h> |
+-----------------------+
Reply With Quote
  #3 (permalink)  
Old 02-04-05, 23:01
old_farmer old_farmer is offline
Registered User
 
Join Date: Feb 2005
Posts: 19
First I want to have:

"start_here"|ldfjlsdffj|93849340|9034093|"end_here "|
"start_here"|ldfjlsdffj|93849340|9034093|"end_here "|

Then I want to remove the "start_here" and "end_here" statements:

ldfjlsdffj|93849340|9034093|
ldfjlsdffj|93849340|9034093|

I guess I could probably do that in one step - this sed stuff is kind of new to me... Hopefully I'll catch on soon...
Reply With Quote
  #4 (permalink)  
Old 02-15-05, 10:48
ducasio ducasio is offline
Registered User
 
Join Date: Aug 2004
Location: Rome, Italy
Posts: 81
Hi old_farmer.
Just use this command line in awk:

awk '{if ($NF=="end_here|") printf "\n"; else if ($NF=="start_here|") printf ""; else printf $0}' test1.txt > test2.txt

You'll have the result you want.

bye bye,
ducasio
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On