The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




Thread: Sed Range Issue
View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 06-05-2008
Wrathe Wrathe is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 6
Sed Range Issue

OK, so for a grand overview of what I'm trying to do:

I've got 2 files that are mostly like.
The file format is:

[descriptor1]
data
data
data
data

[descriptor2]
data
data
data
data

[descriptor3]
data
data

[descriptor4]
data
data

OK, so what I need to do is take all data from [descriptor2] and [descriptor3] sections from file1, remove like sections from file2, and then insert the stream from file1 in the right spot in file2. Fun, right?

Well, I'm new w/ sed, but that seems the best way to do this (correct me if I'm wrong). I've got some code that's working atm, however it's giving me the actual line [descriptor4] as that's the end of the range I'm using and I don't want it to include that in the section delete, how do I not make it do that?

sed '/\[descriptor2/,/\[descriptor4/!d' file1

Basically, I want the output to be:

[descriptor2]
data
data
data
data

[descriptor3]
data
data

And it's giving me all that, plus a [descriptor4] as that's where the range ends, but I'm not sure how else to define it.

Thank you for any light you can shed!