Add header and footer with record count in footer


Login or Register to Reply

 
Thread Tools Search this Thread
# 1  
Old 03-24-2012
Add header and footer with record count in footer

This is my file(Target.txt)
Code:
name|age|locaction
abc|23|del
xyz|24|mum
jkl|25|kol


The file should be like this
Code:
1|03252012
1|name|age|location
2|abc|23|del
2|xyz|24|mum
2|jkl|25|kol
2|kkk|26|hyd
3|4


Column 1 is row indicator
for row 1 and 2, column indicator is 1,for data rows its 2 and for footer its 3.
for footer the record count is is required.

Please help me how to achive it

Last edited by Franklin52; 03-25-2012 at 07:48 AM.. Reason: Please use code tags for data and code samples, thank you
# 2  
Old 03-25-2012
I assume the first row is the current date.
Code:
awk 'BEGIN{"date +%m%d%Y" | getline first; print "1|" first} {if(NR>1){print "2|"$0}else{print "1|"$0} ++c}END{print "3|"c}' infile

Login or Register to Reply

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
Strip header and footer samrat dutta Shell Programming and Scripting 5 06-17-2013 02:08 PM
File Row Line Count without Header Footer gagan8877 UNIX for Dummies Questions & Answers 7 05-02-2013 02:29 PM
Is there a way to append both at header and footer of a file jediwannabe Shell Programming and Scripting 3 02-28-2013 06:57 AM
[solved] how to remove header and footer ment0smintz Programming 0 09-24-2012 04:08 AM
Removing header or footer from file sridhardwh Shell Programming and Scripting 5 06-04-2012 06:43 AM
Removing header and footer Tom Sawyer Shell Programming and Scripting 1 03-07-2012 11:26 AM
Header and Footer... suresh_target Shell Programming and Scripting 1 02-15-2012 04:44 AM
Help with the Header and Footer check Sunny_teotia UNIX for Dummies Questions & Answers 5 06-06-2011 12:14 AM
How to add header and footer? ken002 Shell Programming and Scripting 4 11-22-2010 11:23 PM
Inserting Header and footer digitalrg Shell Programming and Scripting 4 04-17-2009 06:17 AM
Split large file and add header and footer to each small files ashish4422 Shell Programming and Scripting 7 07-07-2008 03:13 PM
Split large file and add header and footer to each file ashish4422 Shell Programming and Scripting 1 04-15-2008 07:12 AM
rowcnt except Header & Footer vsubbu1000 Shell Programming and Scripting 3 08-03-2007 05:50 AM
remove header and footer rows seaky Shell Programming and Scripting 2 11-10-2006 11:18 AM
Need to Chop Header and Footer record from input file coolbudy Shell Programming and Scripting 4 08-09-2005 01:26 PM