Page 1 of 1

Get Header and Trailer record using a single sed command

Posted: Thu Aug 06, 2015 6:38 pm
by RAJARP
Hi ,

I have used sed command successfully in the Filter property of sequential file stage in the past
to get

Code: Select all

 sed -e '1d' -e '$d' 
--> all records without header and trailer

Code: Select all

 sed  '1!d'
--> just the header record

Code: Select all

sed  '$!d'
--> just the trailer record

But I want to get just the header and trailer using a same sed command
So far, I have tried

Code: Select all

  1.sed '1!d;$!d' 
   2.sed -e '1!d' -e '$!d' 

without any luck :oops:

Also, tried sed with -r flag as in sed -r and again no desired output.
Any pointers/help to achieve the same would be much appreciated



Thanks,
Raja

Posted: Thu Aug 06, 2015 7:22 pm
by rkashyap
In the Filter property enter either

Code: Select all

sed -n '1p;$p'
or

Code: Select all

awk 'NR==1;END{print}'

Posted: Fri Aug 07, 2015 11:50 am
by RAJARP
Thanks Kashyap,
Both of the commands worked like charm.Much appreciated :-)