The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Help Inserting data in mysql table vadharah Shell Programming and Scripting 11 03-30-2008 09:26 AM
Inserting Lines between data sets using SED? selkirk Shell Programming and Scripting 1 09-24-2007 11:24 PM
Inserting argument into top of a file Dev06 UNIX for Dummies Questions & Answers 7 10-05-2006 01:16 PM
Inserting a new column in a file rosh0623 UNIX for Advanced & Expert Users 4 08-01-2006 08:15 AM
Inserting a character in a data file jxh461 Shell Programming and Scripting 2 11-04-2002 01:55 PM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-12-2006
Registered User
 

Join Date: Oct 2006
Posts: 6
inserting into a data file

Hello

I have a unix variable $HDR in a script, which contains header info, and I need to create it as a new line at the top of a data file which is the input $1 in the script.

Paul
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 10-12-2006
Registered User
 

Join Date: Oct 2006
Location: Belgium
Posts: 171
Have a look to this thread:
adding text to a file between lines
Reply With Quote
  #3 (permalink)  
Old 10-12-2006
Registered User
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,397
Code:
sed "1 i\
$HDR" $1 >temp
mv temp $1
Reply With Quote
  #4 (permalink)  
Old 10-12-2006
Glenn Arndt's Avatar
Anomalous Lurker
 

Join Date: Feb 2006
Location: Indianapolis, IN
Posts: 255
Sedless version:
Code:
{
  print "$HDR"
  cat $1
} > $1.tmp
mv $1.tmp $1
Reply With Quote
  #5 (permalink)  
Old 10-12-2006
Registered User
 

Join Date: Oct 2006
Posts: 6
Thank you both methods work OK
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 08:43 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0