Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2011
    Posts
    1

    Unanswered: Request for file read option in Unix shell scripting

    Hi Friends,

    I would like to read all the record from one txt file to other file txt

    For example I have two txt file a.txt and b.txt. I need to read a.txt record by record and I need add the system date @ end of each record before moving it to b.txt. Could you please share the coding for this, I am very much new to this language. Thanks in advance.

    Regards,
    Vinoth R

  2. #2
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    Code:
    gawk "{print $0 strftime() }" a.txt >>b.txt
    -PatP
    In theory, theory and practice are identical. In practice, theory and practice are unrelated.

  3. #3
    Join Date
    Sep 2009
    Location
    Ontario
    Posts
    1,057
    Provided Answers: 1
    Code:
    while read line
    do
      echo $line `date` >>b.txt
    done <a.txt
    Notes.
    If the input file is large enough, or the machine is slow enough, the value of the date may change.
    If you want the date to be the same throughout the run:
    Code:
    date=`date`
    while read line
    do
      echo $line $date >>b.txt
    done <a.txt
    If you want to erase b.txt for each run, add
    Code:
    echo "\c" >b.txt
    at the beginning.

  4. #4
    Join Date
    May 2005
    Location
    South Africa
    Posts
    1,365
    Provided Answers: 1
    And another way using sed
    sed "s/$/ `date`/" a.txt >b.txt

Posting Permissions

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