Results 1 to 3 of 3
Hi all,
I am trying to do some one-liner preprocessing on a file with sed. I have two cases like so...
Case 1:
!PRETAG_ Do x to y
Case 2:
...
- 11-28-2007 #1Just Joined!
- Join Date
- Nov 2007
- Posts
- 5
sed help -- merging two lines
Hi all,
I am trying to do some one-liner preprocessing on a file with sed. I have two cases like so...
Case 1:
!PRETAG_ Do x to y
Case 2:
!PRETAG> -- WARNING< DONT REMOVE THIS!
Do x to y
Basically I need to go from case 1 to 2 and back again. I can easily get from 1 to 2, but then re-merging the lines is giving me trouble. My idea was to replace the first line of case 2(including the newline character) with "!PRETAG_ ", thus pulling the next line up to the end of the edited line. However, SED will not pattern match the following: "s/\!PRETAG> -- WARNING< DONT REMOVE THIS!\n/\!PRETAG_ /"
If I hex edit the file, I can clearly see that x0A follows each line, so it seems that sed should match it. I have also attempted to use the "N" feature to no avail.
Any suggestions? I'm pulling out my hair!
Thanks!
- 11-29-2007 #2Linux Enthusiast
- Join Date
- Aug 2006
- Posts
- 631
Should be something like:
RegardsCode:sed ' /!PRETAG> -- WARNING/ { N s/.*\n/!PRETAG_/ }' file
- 11-30-2007 #3Just Joined!
- Join Date
- Nov 2007
- Posts
- 5
Franklin you are correct. The problem that I was experiencing was due to the behavior of the "N" command, I was simply using N on every line, which actually turned out to be every OTHER line, thus my target line was actually being combined with the line BEFORE it instead of AFTER it.
Adding the conditional that N only acts when the TAG is seen fixed my woes! Thanks!


Reply With Quote