Computing.Net > Forums > Unix > Sed - replace block of text - but h

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 - replace block of text - but h

Reply to Message Icon

Name: 18dreams
Date: August 8, 2005 at 06:33:34 Pacific
OS: UNIX
CPU/Ram: NA
Comment:

I am using a sed commmand to replace a block of text over several lines. I do this with a start string and an end string to locate the entire block of text, and replace this section with a single word. The problem I am having is that the output is in all CAPS, I just want to keep the rest of the test as is. Any thoughts? Thanks in advance.

Here is the command: sed -N -e "/^ WARNING\!/,/^IMPRESSION/!p;/Impression/p" $MOD.1 > $MOD.2

Andy




Sponsored Link
Ads by Google

Response Number 1
Name: 18dreams
Date: August 8, 2005 at 06:37:05 Pacific
Reply:

Sorry, the string is:

sed -n -e "/^ WARNING\!/,/^IMPRESSION/!p;/Impression/p" $MOD.1 > $MOD.2

lower case n.

Andy


0

Response Number 2
Name: Jim Boothe
Date: August 8, 2005 at 07:46:00 Pacific
Reply:

That code will not upshift or downshift any of your data, so I do not understand your issue.

The code will print (exactly as is) all lines of data that are NOT within a block of lines beginning with WARNING and ending with IMPRESSION.

It will also print all lines (exactly as is) that contain the string "Impression", which has nothing to do with the IMPRESSION keyword that terminates your defined block of lines since the case is different.  If this line is not within a WARNING/IMPRESSION block, it will get printed once by the first print command and again by this second print command.  If the Impression line is within a WARNING/IMPRESSION block, it will get printed only by the second print command.

So if we have this file:

line 1
line 2 Impression xxx
line 3
 WARNING!
line 5
line 6 Impression yyy
line 7
IMPRESSION
line 9
line 10 Impression zzz
line 11

We would get this output:

line 1
line 2 Impression xxx
line 2 Impression xxx
line 3
line 6 Impression yyy
line 9
line 10 Impression zzz
line 10 Impression zzz
line 11


0

Response Number 3
Name: 18dreams
Date: August 8, 2005 at 08:25:27 Pacific
Reply:

I am sorry, after a closer look, the data in the record is in all caps between impression and end of impression. Somehow in the late hours I couldn't see this. The rest of the record in normal. Sorry, thanks again for your time. I was driving myself crazy looking up sed commands and case.

Again, thanks alot for your help. The very first test I ran must have had normal case for some reason, but every case since has been all caps between the 2 key words.

Thanks!!

Andy


0

Sponsored Link
Ads by Google
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 - replace block of text - but h

replacing occurances of text www.computing.net/answers/unix/replacing-occurances-of-text/4333.html

awk script to extract text www.computing.net/answers/unix/awk-script-to-extract-text/5899.html

seperating out a block of text www.computing.net/answers/unix/seperating-out-a-block-of-text/6088.html