简体   繁体   中英

Combining paste and cat in unix

I have files with this name format:

<name1>.<name2>.<id>.ERR

where name1 and name2 are character string s and id is a number and all three are unique to each file. (these are standard output files from a slurm run, and id is the job id).

I want to find out if these jobs failed so I was thinking of cut 'ing id from each file name:

ls -1 *.ERR | cut -d "." -f 3

And then pasting "sacct -j " in front of it. Is there a one liner that achieves this so that it runs:

sacct -j id 1

sacct -j id 2

.
.

sacct -j id n

Something like:

for id in $(ls *.ERR | cut -d "." -f 3); do echo "machine: $id"; done

will work, if the files are not a lot (thousands). Replace echo blah blah with sacct -j, like this:

for id in $(ls *.ERR | cut -d "." -f 3); do sacct -j $id; done

There are other ways too.

You can simply use xargs :

ls -1 *.ERR | cut -d "." -f 3 | xargs -L 1 sacct -j 

which you can run in parallel with the -P option to alleviate a bit the latency from interrogating the database.

ls -1 *.ERR | cut -d "." -f 3 | barges -P 4 -L 1 sacct -j 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM