Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help with SED Command (Copying Ranges by number)

Status
Not open for further replies.

BobWaterhouse

Programmer
Dec 11, 2002
27
US
I am trying to copy a file based on line numbers within the files. I can figure the To and From numbers by using grep, but, when trying to copy that specific range, I'm erroring out. I've tried a few ways, but, to know avail. Here's an example..

sed -n $STSTART','$STEND' p' $temp4 >> $temp5

sed -n "$STSTART,$STEND p" $temp4 >> $temp5

sed -n "$STSTART","$STEND" p $temp4 >> $temp5

Also, is this not a true range, but, the starting line and the length to copy?

Any help would be appreciated.
 
Would also be VERY helpful if I could delete a range of line numbers from a file also....

So ultimately, I would copy the range to one file, then eliminate that range in another.
 
Try this:

sed -n "$START,${STOP}p" $temp4 > $temp5

to delete a range:

sed "$START,${STOP}d" file1 > file2


-jim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top