Computing.Net > Forums > Unix > sed - How to do conditional line in

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

sed - How to do conditional line in

Reply to Message Icon

Name: jlhughey
Date: October 17, 2006 at 10:05:54 Pacific
OS: AIX 5.3
CPU/Ram: 2.3 GHz / 2 TB
Product: IBM/System p595
Comment:

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
z

After:
x
b
y
b
z
Example 2:

Before:
x
c
y
z

After:
x
c
y
b
z

Thanks for your help!


Joseph



Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: October 18, 2006 at 11:27:58 Pacific
Reply:

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:

http://www.student.northpark.edu/pe...


0
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: sed - How to do conditional line in

how to replace a line in a file www.computing.net/answers/unix/how-to-replace-a-line-in-a-file/7214.html

How to do data cleansing in unix www.computing.net/answers/unix/how-to-do-data-cleansing-in-unix/7068.html

how to replace a file in a .zip fil www.computing.net/answers/unix/how-to-replace-a-file-in-a-zip-fil/7497.html