0

I have a list of files in a directory with extension .gz and for that same list I need to grep from final.log and get the same file name.gz.DONE name by using grep and need to search for the entire list of files from the directory, so that I can prepare a touch -d command from using .gz.DONE.

Example:

VIC_sentine_1153690_20220503_153250_0000.psv.gz
VIC_sentine_1151176_20220504_153250_0000.psv.gz
VIC_sentine_175390_20220505_153250_0000.psv.gz

from the .log file.

When I do grep below like this

a=VIC_sentine_1153690_20220503_153250_0000.psv.gz

cat ~/final.log | grep $a | grep DONE | cut -d '/'  -f 7 | head -n 1

I get VIC_sentine_1153690_20220503_153250_0000.psv.gz.20220523081154.DONE

by using .DONE file, the timestamp from the same .gz in the directory I'm generating manually

touch -d "2022-05-03 21:04:00.000000000" VIC_sentine_1153690_20220503_153250_0000.psv.gz.20220523081154.DONE

but there are 200 files in the directory.

Is there a way to cross check the .gz file with the same .gz.*DONE (as there are some numeric involved between .gz & .DONE) exists?

If not then generate a touch command and output that command to some .txt file. All I need is to generate touch commands dynamically from that directory by grepping to the log file.

2
  • It looks like this is some kind of job queue - is that correct? I don't have an answer for you at this stage, just a few comments/suggestions. 1. It's generally better to move completed job files to a different directory (or just delete them if you don't need them) - i.e. instead of touching a .DONE file, just mv the file to a done/ directory. 2. cat | grep | grep | cut | head is just awful. try awk -F/ -v a="$a" '$0 ~ a && /DONE/ {print $7; last}' ~/final.log instead. 3. Depending on what your job queue process does, it's probably better to use awk, perl, or python than shell.
    – cas
    Jun 1 at 10:04
  • Also, GNU touch has a -r (--reference) option that you can use to touch a file to have the same timestamp as another file, so you don't need to generate a timestamp for -d manually.
    – cas
    Jun 1 at 10:10

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.