1753521 Members
4625 Online
108795 Solutions
New Discussion юеВ

Shell script

 
Srinivas_20
New Member

Shell script

Could you please help me out for a better and simple Unix script for the following conditions:
The input file (either fixed length or tab delimited) contains a header (i.e. first line) and footer (i.e. last line), and detail records. Each header contains constant value of '10' and each footer contains a constant value of '99'. The input file should be split into 2 files, one file with only header and footer, and the second file with only detail records.
6 REPLIES 6
Paula J Frazer-Campbell
Honored Contributor

Re: Shell script

HI

Can you attach an example file ?

Paula
If you can spell SysAdmin then you is one - anon
James R. Ferguson
Acclaimed Contributor

Re: Shell script

Hi:

# sed -n -e /10/p -e /99/p file.in > file.hdr

# sed -e /10/d -e /99/d file.in > file.details

Regards!

...JRF...
Justo Exposito
Esteemed Contributor

Re: Shell script

Hi,

Grep version:

grep -v -e "10" -e "99" infile > outfile
grep -e "10" -e "99" infile > outfile

Regards,

Justo.
Help is a Beatiful word
James R. Ferguson
Acclaimed Contributor

Re: Shell script

Hi:

If you prefer a general script that snips the first and last lines from a file, regardless of content, use something like:

# sed -n -e '1p' -e '$p' file.in > file.hdr

# sed -e '1d' -e '$d' file.in > file.det

Regards!

...JRF...
Srinivas_20
New Member

Re: Shell script

Thank you guys for your quick response. Anyway here is the sample output file that it looks like
10 MSV024 20020822 175149
20 40392 Jones,Donald P 46916 7290 6545315 107 EDA
20 42409 Miller,Jacob S 32384 7290 6545315 107 KEA
20 44656 Davis,Rick 38608 1011 7950607 006 116
20 45908 Smith,Cary 40476 9505 9005165 011 616
99 4
Rodney Hills
Honored Contributor

Re: Shell script

You've had several responses that look like they should work. Since you haven't assigned points, I assume that none of the solutions provided are what you are looking for.

Now that you have supplied the data, the above solutions can be made to work by putting a "^" in front of the "10" and one in front of the "99", since these numbers appear at the front of the line.

Was their something else that you wanted done to the data?

-- Rod Hills
There be dragons...