The UNIX and Linux Forums  

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 here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how to add files to an existing tar file - HP-UNIX Nomaad UNIX for Dummies Questions & Answers 5 3 Weeks Ago 02:27 AM
Replacing the last data of each line ina file jisha Shell Programming and Scripting 6 08-04-2008 04:47 AM
add data from command line to end of file bryan UNIX for Dummies Questions & Answers 3 05-23-2006 03:57 PM
Print one line of Existing File danhodges99 UNIX for Dummies Questions & Answers 2 02-25-2003 08:56 AM
help on appending data to existing data precious51980 UNIX for Dummies Questions & Answers 1 01-27-2001 09:56 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 01-20-2006
Registered User
 

Join Date: Jan 2006
Posts: 19
Need to add a line of data to already existing file in Unix..

Hello..

I have a text file with 100 lines of data.
I need to add 1 line of data to that already existing file at the first line( beginning of the file) , so that the already existing 100 lines will start from 2 nd line.Now the file will have 101 lines of data.

Help me on how to add the line of data ??

--Charan..
Reply With Quote
Forum Sponsor
  #2  
Old 01-20-2006
Registered User
 

Join Date: Dec 2005
Location: India
Posts: 218
Hi,

I am a newbee as well,

I think u can do it in followig ways,

1) open the file in VI and add the first line at the top
2) put the new line into another file say file2 and then

do
cat file2 exsistingfile > newfile

newfile is your output

grp please correct me if i m wrong

bye
Gaurav
Reply With Quote
  #3  
Old 01-20-2006
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,610
Code:
echo "1i\nthis is the line that u wanted to insert \n.\nwq" | ex -s filename
Reply With Quote
  #4  
Old 01-20-2006
zazzybob's Avatar
Registered Geek
 

Join Date: Dec 2003
Location: Melbourne, Australia
Posts: 2,100
with sed...
Code:
sed '1 i\
new first line' file > newfile && mv newfile file
with perl (edit file in place)...
Code:
perl -p -i -e '$_ = "new first line\n$_" if ( $. == 1 );' file
Cheers
ZB
Reply With Quote
  #5  
Old 01-21-2006
Registered User
 

Join Date: Jan 2006
Posts: 19
Madhan,

When i use

echo "1i\nGROUP_NAME,JOB_NAME,STATUS,PROCESS_GROUP,JOB_START,JOB_END \n.\nwq" | ex -s abc.txt

where abc.txt contains only
Hello
Testing
Insert

I am getting this..

dumb: Unknown terminal type
ksh: 19464 Segmentation Fault


Is that a major error..If so, How to overcome ??
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 10:46 PM.


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

Content Relevant URLs by vBSEO 3.2.0