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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sed - Capture results from a data file? 1

Status
Not open for further replies.

wellster34

Programmer
Sep 4, 2001
113
CA
Hi,

I have a data file (input_file.dat):

BEGIN DATA EXTRACT
1|AUG-05|10002|2260388115.38|-4151079.23|2256237036.15|0|0
1|SEP-05|10002|2256237036.15|-4612568.24|2251624467.91|0|0
1|AUG-05|10002|1843860115.32|61745489.54|1905605604.86|0|0
1|SEP-05|10002|-488569233.24|0|-488569233.24|0|0
END DATA EXTRACT


I need to capture the results between the HEADER (BEGIN DATA EXTRACT) and the FOOTER (END DATA EXTRACT) via a unix command(s).

Is there a sed command or some other command to perform this?

I have tried the following command:

sed '/BEGIN DATA EXTRACT/d;/END DATA EXTRACT/q' input_file.dat > new_input_file.dat

and it gives me the following results:
1|AUG-05|10002|2260388115.38|-4151079.23|2256237036.15|0|0
1|SEP-05|10002|2256237036.15|-4612568.24|2251624467.91|0|0
1|AUG-05|10002|1843860115.32|61745489.54|1905605604.86|0|0
1|SEP-05|10002|-488569233.24|0|-488569233.24|0|0
END DATA EXTRACT


This is a step in the right direction but is there a way to remove the footer???


Any ideas would be greatly appreciated!!!


Thanks for your time
 
sed '/BEGIN DATA EXTRACT/d;/END DATA EXTRACT/{;d;q;}' input_file.dat > new_input_file.dat

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Not to detract from PHV's solution because it is elegant. However, it only works if the BEGIN DATA EXTRACT is the first line and END DATA EXTRACT is the last line. If any other lines exist outside the BEGIN DATA EXTRACT and END DATA EXTRACT, they also print.

I don't want to elaborate on the obvious, but why not just delete the first and last lines of the file:

Code:
sed -e '1d' -e '$d' input_file.dat
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top