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

Sed - replace block of text - but h

Reply to Message Icon

Original Message
Name: 18dreams
Date: August 8, 2005 at 06:33:34 Pacific
Subject: Sed - replace block of text - but h
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



Report Offensive Message For Removal


Response Number 1
Name: 18dreams
Date: August 8, 2005 at 06:37:05 Pacific
Subject: Sed - replace block of text - but h
Reply: (edit)

Sorry, the string is:

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

lower case n.

Andy


Report Offensive Follow Up For Removal

Response Number 2
Name: Jim Boothe
Date: August 8, 2005 at 07:46:00 Pacific
Subject: Sed - replace block of text - but h
Reply: (edit)

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


Report Offensive Follow Up For Removal

Response Number 3
Name: 18dreams
Date: August 8, 2005 at 08:25:27 Pacific
Subject: Sed - replace block of text - but h
Reply: (edit)

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


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Sed - replace block of text - but h

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software