The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Unix Arithmatic operation issue , datatype issue thambi Shell Programming and Scripting 23 02-19-2008 07:19 AM
specifing range.... zedex UNIX for Advanced & Expert Users 1 10-19-2007 09:07 AM
Getting 'out of range' when partitioning pmichner UNIX for Dummies Questions & Answers 1 09-30-2006 01:51 AM
Look a string within a range! azmathshaikh Shell Programming and Scripting 0 05-01-2005 03:54 AM
Unix SCO 5.0.6 Out of range josramon UNIX for Dummies Questions & Answers 5 02-21-2003 02:06 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #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!
  #2 (permalink)  
Old 06-05-2008
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,212
Try this:

Code:
awk ' 
FNR==NR && /descriptor2/{f=1} 
FNR==NR && /descriptor4/{f=0} 
FNR==NR && f{arr[++i]=$0}
FNR==NR{next}
/descriptor2/{for(j=1;j<=i;j++){print arr[j]};f=1} 
/descriptor4/{f=0} 
!f{print}
' "file1" "file2"
Regards
  #3 (permalink)  
Old 06-17-2008
freelong freelong is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 38
Code:
sed -e '/\[descriptor2/,/\[descriptor4/!d' -e '/\[descriptor4/d' file1
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 06:29 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0