Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 02-28-2013
Registered User
 
Join Date: Nov 2012
Posts: 43
Thanks: 6
Thanked 0 Times in 0 Posts
Is there a way to append both at header and footer of a file

currently I've a file


Code:
Insert into CD_CARD_TYPE
   (CODE, DESCRIPTION, LAST_UPDATE_BY, LAST_UPDATE_DATE)
 Values
   ('024', '024', 2, sysdate);
Insert into CD_CARD_TYPE
   (CODE, DESCRIPTION, LAST_UPDATE_BY, LAST_UPDATE_DATE)
 Values
   ('032', '032', 2, sysdate);
........

is it possible to add the following such that output will become as follow:


Code:
prompt loading CD_CARD_TYPE
Insert into CD_CARD_TYPE
   (CODE, DESCRIPTION, LAST_UPDATE_BY, LAST_UPDATE_DATE)
 Values
   ('024', '024', 2, sysdate);
Insert into CD_CARD_TYPE
   (CODE, DESCRIPTION, LAST_UPDATE_BY, LAST_UPDATE_DATE)
 Values
   ('032', '032', 2, sysdate);
........
prompt done loading

understand that we can append anything to the footer of a file by doing the following

echo "prompt done loading" > filename.txt but how about appending the header?

thanks a lot!
Sponsored Links
    #2  
Old 02-28-2013
Registered User
 
Join Date: Nov 2012
Posts: 162
Thanks: 13
Thanked 10 Times in 10 Posts
Try this for header.


Code:
sed '1i\
your text' file_name

Sponsored Links
    #3  
Old 02-28-2013
RudiC RudiC is offline Forum Advisor  
Registered User
 
Join Date: Jul 2012
Location: Aachen, Germany
Posts: 2,028
Thanks: 25
Thanked 459 Times in 444 Posts
Quote:
Originally Posted by jediwannabe View Post
. . .
understand that we can append anything to the footer of a file by doing the following

echo "prompt done loading" > filename.txt but how about appending the header?

thanks a lot!
If you do that, your filename.txt will be gone. Use >> for appending.
Put header in a headerfile and then cat headerfile filename.txt
    #4  
Old 02-28-2013
Registered User
 
Join Date: Sep 2012
Posts: 21
Thanks: 5
Thanked 1 Time in 1 Post
Try this

Code:
sed '1i\
header
$a\
footer' filename

Sponsored Links
Reply

Tags
append header shell bash ksh

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Removing header or footer from file sridhardwh Shell Programming and Scripting 5 06-04-2012 05:43 AM
Add header and footer with record count in footer itsranjan Shell Programming and Scripting 1 03-24-2012 11:45 PM
sort a report file having header and footer suryanarayana Shell Programming and Scripting 4 11-25-2011 09:48 PM
Append Spaces At end of each line Leaving Header and Footer deepam Shell Programming and Scripting 1 10-21-2008 04:08 AM
Total of lines w/out header and footer incude for a file gzs553 Shell Programming and Scripting 1 11-16-2006 06:42 PM



All times are GMT -4. The time now is 09:33 AM.