Hi ,
My UNIX system is SUN Solaris.
I am trying to do a simple thing as described below.
I have a PIPE delimited file that has header and trailer. So the file is something like below:
Test1.txt looks like something below:
field_data1|field_data2|and some more data --Header
Field1|field2|....and so on -Main data
T|some info --Trailer
I want to perform the things below in this file:
Remove the trailer from Test1.txt
Save the header from Test1.txt
Sort the records in Test1.txt excluding header (and run some business operation already in place on Test1.txt) that will create a subset pipe delimited file say Test2.txt
Sort Text2.txt by field 2 and 3
Add the header from step2(above) in Test2.txt
So the output should be Test2.txt -sorted by field 2 and 3 and add the header from step2.
{ head -1 ; head -n-1 | sort -t"|" -k2,3; } [..]
I wanted to check if there is a way to output without header as well.
Try:
sed '1d;$d' Test1.txt | sort -t\| -k2,3 > Test2.txt