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 > File write command

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-04-04, 12:08
aravindvin aravindvin is offline
Registered User
 
Join Date: Feb 2004
Posts: 22
Question File write command

I need a shell script for the following logic. Can anyone pls. help me?

1. Read a file <x.dat> having some data
2. Check if the output file <y.dat> exists and has data
3. If <y.dat> exists then append data to <y.dat>
4. Else create new <y.dat>

Datafile: x.dat
10:00 Batch run1.exe
11:00 Batch run2.exe
12:00 Batch run3.exe

Datafile y.dat (if exists)
05:00 Batch run99.exe
04:00 Batch run98.exe

Thanks and Regards.,
Aravind
Reply With Quote
  #2 (permalink)  
Old 05-04-04, 23:28
saurav101 saurav101 is offline
Registered User
 
Join Date: Oct 2003
Posts: 19
Try this
terminal=`tty`
exec < x.dat
while read line
do
if [ -z y.dat ]
then
echo $line >>y.dat
else
echo $line >y.dat
fi
done

exec <$terminal
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