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 > Request for file read option in Unix shell scripting

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-01-11, 13:10
vinoth124 vinoth124 is offline
Registered User
 
Join Date: Jun 2011
Posts: 1
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
Reply With Quote
  #2 (permalink)  
Old 06-01-11, 14:35
Pat Phelan Pat Phelan is online now
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,612
Code:
gawk "{print $0 strftime() }" a.txt >>b.txt
-PatP
__________________
In theory, theory and practice are identical. In practice, theory and practice are unrelated.
Reply With Quote
  #3 (permalink)  
Old 06-01-11, 14:38
kitaman kitaman is offline
Papabi's friend
 
Join Date: Sep 2009
Location: Ontario
Posts: 629
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.
Reply With Quote
  #4 (permalink)  
Old 06-02-11, 03:12
pdreyer pdreyer is offline
Registered User
 
Join Date: May 2005
Location: South Africa
Posts: 1,268
And another way using sed
sed "s/$/ `date`/" a.txt >b.txt
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