Parsing quoted filenames with xargs/awk


Results 1 to 2 of 2

Thread: Parsing quoted filenames with xargs/awk

  1. #1
    Join Date
    Apr 2005
    Posts
    2

    Parsing quoted filenames with xargs/awk

    I'm trying to save the modification times for a group of files so I can edit the files and then restore the times, but I'm having problems because some of the filenames have whitespaces.

    Using the command 'ls -lQ --time-style=+%Y%m%d%H%M.%S *.txt | cut -c 44- > modtime', I get a file containing the time and quoted filename:

    Code:
    200504012006.15 "file 3.txt"
    200504011932.12 "file1.txt"
    200504011934.06 "file2.txt"
    'touch *.txt' sets the times for all the files to the current time. Then, I can use 'touch -mt 200504012006.15 "file 3.txt"' to set the time for that file. I've tried to automate it with xargs and awk so I can just use one command to restore all the times, but I haven't really made any progress. Any suggestions?

    Thanks.

  2. #2
    Join Date
    Apr 2005
    Posts
    2
    I looked through the xargs man page again, and the -n switch was what I was looking for. In case anyone can use it, this is what seems to be working:

    Code:
    find -name '*.txt' -printf '%TY%Tm%Td%TH%TM.%TS\t"%p"\n' > modtime
    
    xargs -n2 touch -mt < modtime

Posting Permissions

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