If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > insert to an empty file

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-23-04, 04:27
viranihardik viranihardik is offline
Registered User
 
Join Date: Mar 2004
Posts: 11
insert to an empty file

Hi,
I need to insert something into an empty file

touch newfile
sed -f insertcode newfile


where insertcode is
1i\
first line;


But the file still remains empty.Could someone tell me what's wrong out here?


Also can I write a variable in insertcode? eg.

define VARIABLE
touch newfile
sed -f insertcode newfile

where insertcode is
1i\
first line with VARIABLE;


Thanks
Reply With Quote
  #2 (permalink)  
Old 03-23-04, 04:43
aigles aigles is offline
Registered User
 
Join Date: Jan 2004
Location: Bordeaux, France
Posts: 319
sed doesn't modify the input file, it writes the result to stdout.
You must redirect the output of sed into a file :

sed -f insertcode newfile > new_newfile


If you just want to insert datas in an empty file don't use sed.

Code:
Variable="contents of Variable"
echo "First line;"    > newfile
echo "Second line;"   >> newfile
echo "Last line with $Variable" >> newfile
> newfile : reset newfile and redirect stdout to newfile
>> newfile : redirect stdout to newfile in append mode

another method:
Code:
Variable="contents of Variable"
cat <<EOD_CAT >newfile
First line;
Second line;
Last line with $Variable
EOD_CAT
__________________
Jean-Pierre.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On