Is there a way to append both at header and footer of a file | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


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

Is there a way to append both at header and footer of a file

Shell Programming and Scripting


Tags
append header shell bash ksh

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 02-28-2013
jediwannabe jediwannabe is offline
Registered User
 
Join Date: Nov 2012
Last Activity: 13 June 2014, 2:43 AM EDT
Posts: 50
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
Vikram_Tanwar12 Vikram_Tanwar12 is offline
Registered User
 
Join Date: Nov 2012
Last Activity: 21 November 2013, 3:32 AM EST
Posts: 168
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
Last Activity: 20 August 2014, 6:24 AM EDT
Location: Aachen, Germany
Posts: 4,082
Thanks: 66
Thanked 969 Times in 919 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
chacko193 chacko193 is offline
Registered User
 
Join Date: Sep 2012
Last Activity: 20 August 2014, 8:59 AM EDT
Posts: 183
Thanks: 30
Thanked 31 Times in 31 Posts
Try this

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

Sponsored Links
Closed Thread

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 10:34 AM.