Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2004
    Posts
    22

    Question Unanswered: 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

  2. #2
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •