Find the answer to your Linux question:
Results 1 to 3 of 3
From a daily file the constituent data needs to be extracted and the resulting file should be renamed. These are the components: Data extraction: cut -d, -f 1,28,29 foo.csv > ...
  1. #1
    Linux User
    Join Date
    Dec 2004
    Posts
    323

    Renaming a file: adding a date

    From a daily file the constituent data needs to be extracted and the resulting file should be renamed. These are the components:

    Data extraction:
    cut -d, -f 1,28,29 foo.csv > foo.txt

    Renaming: the following file is executed:
    #!/bin/sh
    dt=`date +%Y%m%d`
    cp foo.txt foo$dt.txt

    How can the steps be combined into one line?

    Thank you for your information in advance

  2. #2
    Linux Engineer Kieren's Avatar
    Join Date
    Aug 2007
    Location
    England
    Posts
    845
    Use $() to wrap around your executable code:

    Code:
    cut -d, -f 1,28,29 foo.csv > foo$(date +%Y%m%d).txt
    Linux User #453176

  3. #3
    Linux User
    Join Date
    Dec 2004
    Posts
    323
    Thanks, that worked.

Posting Permissions

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