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
how to add files to an existing tar file - HP-UNIX Nomaad UNIX for Dummies Questions & Answers 5 11-06-2008 05:27 AM
Replacing the last data of each line ina file jisha Shell Programming and Scripting 6 08-04-2008 07:47 AM
add data from command line to end of file bryan UNIX for Dummies Questions & Answers 3 05-23-2006 06:57 PM
Print one line of Existing File danhodges99 UNIX for Dummies Questions & Answers 2 02-25-2003 11:56 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 Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-20-2006
charan81 charan81 is offline
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..
  #2 (permalink)  
Old 01-20-2006
gauravgoel gauravgoel is offline
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
  #3 (permalink)  
Old 01-20-2006
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,944
Code:
echo "1i\nthis is the line that u wanted to insert \n.\nwq" | ex -s filename
  #4 (permalink)  
Old 01-20-2006
zazzybob's Avatar
zazzybob zazzybob is offline Forum Advisor  
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
  #5 (permalink)  
Old 01-21-2006
charan81 charan81 is offline
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 ??
Sponsored Links
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 04:27 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