0

To monitor the job status in clusters, qstat is used to output lines like this

job-ID  prior   name       user         state submit/start at     queue                          slots ja-task-ID
-----------------------------------------------------------------------------------------------------------------
 146767 2.75000 REMD       xxxxxx      Rr    03/26/2021 10:58:17 [email protected]   160
 146811 2.75000 REMD       xxxxxx      r     03/26/2021 11:37:48 [email protected]   160
 146862 2.25862 REMD       xxxxxx      Rq    03/26/2021 06:24:39                                  160
 146911 2.19397 REMD       xxxxxx      Rq    03/26/2021 11:37:20                                  160
 146768 0.00000 REMD       xxxxxx      hqw   03/13/2021 14:47:35                                  160
 146769 0.00000 REMD       xxxxxx      hqw   03/13/2021 14:47:35                                  160
 146770 0.00000 REMD       xxxxxx      hqw   03/13/2021 14:47:36                                  160

The first element of each line is the job ID. Is there a way to show the lines for a particular range of jobs, e.g. how to only show the jobs from 146868 to 146927? It seems that grep is needed.

Jeff Schaller
  • 66,199
  • 35
  • 114
  • 250
lanselibai
  • 133
  • 2
  • 5

2 Answers2

2

While you could construct regexes to match a range of numbers, it's really not worth it. Better use some tool that can deal with numbers as numbers. E.g. in awk this is rather trivial. Here, a and b are the lower and upper limits respectively, and $1 is the first field, by default split along white space.

$ qstat | awk -v a=146868 -v b=146927 '$1 >= a && $1 <= b {print}'
 146911 2.19397 REMD       xxxxxx      Rq    03/26/2021 11:37:20                                  160

(In ERE, the equivalent regex would be something like 146(86[89]|8[789][0-9]|9[01][0-9]|92[0-7]), unless I made a mistake there, which is not unlikely. In BRE, it's impossible since there's no alternation.)

ilkkachu
  • 133,243
  • 15
  • 236
  • 397
  • Do I need to have ```qstat```? Should it be```< file.txt``` or ```> file.txt```? I got ```-bash: file.txt: No such file or directory``` message when using ```< file.txt``` – lanselibai Mar 26 '21 at 13:04
  • @lanselibai, right, I focused on just the awk and implicitly assumed input from a file. To filter the output of some command, you'd use e.g. `qstat | awk ...` the same as you'd use `qstat | grep ...`. Of course you could do `qstat > file.txt` and then `awk ... < file.txt`, or `grep ... < file.txt` – ilkkachu Mar 26 '21 at 15:12
0

I found a simple solution:

qstat | fgrep "$(seq 146868 146927)"

lanselibai
  • 133
  • 2
  • 5