Find the answer to your Linux question:
Results 1 to 3 of 3
I want to add a date to a record which is added to a file that gets its data from an external source. An explanation: 1. Getting external data: curl ...
  1. #1
    Linux User
    Join Date
    Dec 2004
    Posts
    323

    Adding a date as a column to a file

    I want to add a date to a record which is added to a file that gets its data from an external source. An explanation:

    1. Getting external data: curl http://www.download.com/scores.txt

    2. Getting the required record: | grep myteam

    3. Appending to file: >> myscores.txt

    The question is not only to append the scores, but to add a column with the current date and time. So I need to add something like "$( date +%Y%m%d%H%M%S )" as the first column to scores.txt. How is this done?

    Thanks in advance

  2. #2
    Linux User
    Join Date
    May 2008
    Location
    NYC, moved from KS & MO
    Posts
    251
    suppose the output of step 2 is /tmp/tmp_line, then the following command should do the job for you:
    ( date | tr '\012' '\t' ; cat /tmp/tmp_line )>>myscores.txt
    '\t' is the separator between date and the score data, replace it with whatever you want. Add formatting string after date if you need to.

  3. #3
    Linux User
    Join Date
    Dec 2004
    Posts
    323
    Thanks, that worked after some more tweaking.

Posting Permissions

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