By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,821 Members | 1,043 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,821 IT Pros & Developers. It's quick & easy.

Help : Unix Add date to a file on every begining of line from other text file

P: 1
Hi ,

I'm still newbie
Anyone can help me for putting date into a file which grep from other file? I use sed command but it gets error since the date format determine as a command. Here is the case :

"text1.tmp" contains :
Post Date 07/01/2008

"text2.tmp" contains :

1234562 45.0 xxxxxx
4452234 50.0 zzzzzz

How to use get only the date from text1 and add to every begining of the line of text2.tmp as below ?

07/01/2008 1234562 45.0 xxxxxx
07/01/2008 4452234 50.0 zzzzzz

thanks in advanced before.
Feb 15 '08 #1
Share this Question
Share on Google+
1 Reply

ashitpro
Expert 100+
P: 542
Hi ,

I'm still newbie
Anyone can help me for putting date into a file which grep from other file? I use sed command but it gets error since the date format determine as a command. Here is the case :

"text1.tmp" contains :
Post Date 07/01/2008

"text2.tmp" contains :

1234562 45.0 xxxxxx
4452234 50.0 zzzzzz

How to use get only the date from text1 and add to every begining of the line of text2.tmp as below ?

07/01/2008 1234562 45.0 xxxxxx
07/01/2008 4452234 50.0 zzzzzz

thanks in advanced before.

Here we go..
Next code will give you the output file as text3.tmp
Expand|Select|Wrap|Line Numbers
  1. my_date=`grep -o '../../....' text1.tmp`
  2. for i in `cat text2.tmp`
  3. do
  4.     echo $my_date $i >> text3.tmp
  5. done
  6.  
Feb 15 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.