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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • geblex
    New Member
    • Feb 2008
    • 1

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

    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.
  • ashitpro
    Recognized Expert Contributor
    • Aug 2007
    • 542

    #2
    Originally posted by geblex
    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
    Code:
    my_date=`grep -o '../../....' text1.tmp`
    for i in `cat text2.tmp`
    do
        echo $my_date $i >> text3.tmp
    done

    Comment

    Working...