I want to Sort the data in fixed width file where i have Header and Footer also in file.
I m using below commad to do the sort based on field satarting from 15 position to 17 position , but it is not ignoring the Header and Footer of the file while sorting. In the output i am getting both header and footer coming in first and then the data. It is sorting header and footer records also.
You could alternatively redirect stdout to a file before starting the commands above, then reset it to your terminal:
H=$(head -1 infile)
T=$(tail -1 infile)
exec 1> newfile careful, all following output to stdout will now be redirected into that file "newfile" until reset!
echo $H; sed '1d;$d' infile| sort -t'|' -k1.15,1.17; echo $T
exec 1> /dev/tty resetting stdout to your terminal