Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I am running a text file through a sequence of sed scripts, but one clean operation escapes me.
I want conditionally insert a blank line between *any two* uniquely indentifiable lines, *only if* a non-unique comment is *not* between them. I know in advance what the unique starting patterns of these lines (x, y, z below) are. A maximum of one comment line is between the unique lines.
Alternatively, I suppose I could insert blank lines between every line, then conditionally delete them in the next sed run; however let's try the insert scheme if possible.
Here are a couple of examples:
Legend:
x, y, z "Label" lines with unique and sequential labels (ie - 01160 , 01234 title2)
c a line with random comments.
b a blank line, or a single character such as a pipe "|"Example 1:
Before:
x
y
zAfter:
x
b
y
b
z
Example 2:Before:
x
c
y
zAfter:
x
c
y
b
zThanks for your help!
Joseph

It looks like this problem is solved easily enough with a tool that allows processing a line at a time - such as awk or perl.
However, I think sed is not the best choice. Why? Because implementing if type comparisons in sed is not easy. Check out this link, IF/ELSE TESTING IN SED:

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |