The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Appending a line in a file after a particular line maxvirrozeito Shell Programming and Scripting 7 12-12-2007 01:58 PM
capturing line from script output and appending to a file wally_welder Shell Programming and Scripting 6 08-31-2007 03:03 AM
Appending line ending with '}" to new line aismann Shell Programming and Scripting 4 08-13-2007 02:09 AM
Appending the line number and a seperator to each line of a file ? pjcwhite Shell Programming and Scripting 4 03-21-2007 01:29 AM
help on appending data to existing data precious51980 UNIX for Dummies Questions & Answers 1 01-27-2001 12:56 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-03-2007
brainstormer brainstormer is offline
Registered User
  
 

Join Date: Jan 2007
Posts: 1
Lightbulb Appending data at the first and last line of a file

Hi,

Am trying to write a shell script which will append a header and a footer to an existing file. Header will contain details like the current date while the footer will contain the no: of records listed in the file.

I know we can use the CAT command, but i have no clue abt the syntax to append to the start and end of a file . Any help will be appreciated!
  #2 (permalink)  
Old 01-03-2007
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398
Code:
sed "1i\\
header info" file |
sed "$a\\
footer info" >tmp
mv tmp file
  #3 (permalink)  
Old 01-03-2007
ranj@chn ranj@chn is offline Forum Advisor  
Playing with Ubuntu Now!
  
 

Join Date: Oct 2005
Location: Chennai
Posts: 365
awk one

Code:
awk 'BEGIN{print "header"} {print} END {print "trailer"}' filename >tmpfile
mv tmpfile filename
  #4 (permalink)  
Old 01-03-2007
ranj@chn ranj@chn is offline Forum Advisor  
Playing with Ubuntu Now!
  
 

Join Date: Oct 2005
Location: Chennai
Posts: 365
a little more specific

awk 'BEGIN {system("date")} {print} END { print "No of records -",NR}' filename >tmpfile
  #5 (permalink)  
Old 01-03-2007
Glenn Arndt's Avatar
Glenn Arndt Glenn Arndt is offline Forum Advisor  
Anomalous Lurker
  
 

Join Date: Feb 2006
Location: Indianapolis, IN
Posts: 255
Code:
{
  print "This is the header"
  cat file
  print "This is the footer"
} > file.new
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




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


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0