#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2003
    Posts
    147
    Rep Power
    12

    Use for loop or awk?


    I have a tab delimited file with 2 columns.

    2224 23943843
    5494 39843843
    8372 48938384

    I have to loop through this file and copy the files with the first field to a new name that contains both the first and second field.
    To be more specific,
    file quote2224.pdf has to be copied to 23943843_quote2224.pdf
    file quote5494.pdf has to be copied to 39843843_quote5494.pdf

    What's the best way to do this?
    I don't know how or if it's even possible to use a for loop and access both fields.
    I don't know how to copy files in awk.

    Thanks.
    Last edited by achieve; March 17th, 2011 at 04:06 PM.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2007
    Posts
    44
    Rep Power
    11
    Here's a very quick&dirty way to do this. Supposing that your original tab-delimited file is named 'tabfile', try the following:

    Code:
    while read first second
    do   
      cp quote${first}.pdf ${second}_quote${first}.pdf
    done < tabfile
    This is by no means pretty, elegant or the most efficient way to do this - but it's simple.

IMN logo majestic logo threadwatch logo seochat tools logo