Search code examples
unixpastecut

Combining paste and cat in unix


I have files with this name format:

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

where name1 and name2 are character strings 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 id1

sacct -j id2

.
.

sacct -j idn


Solution

  • 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.