How to skip the first line of my output?

You can supress the header line from squeue with the -h-option. That would eliminate the need to remove the first row.

From the man page of squeue:

-h, --noheader
    Do not print a header on the output.

There are many many ways to do this, the first I thought of was:

squeue -u user_name | tail -n +2 | wc -l

From the man page for tail:

-n, --lines=[+]NUM            output the last NUM lines, instead of the last 10;
                              or use -n +NUM to output starting with line NUM

So fo you -n +2 should skip the first line.

You can also use the sort form of tail: tail +2


Just for fun. You can subract 1 from the wc output

echo $(( $(squeue -u user_name|wc -l)-1 ))

or

squeue -u user_name|wc -l|awk '{print $0-1}'

When you use awk you can count the lines with awk and so avoid wc

squeue -u user_name|awk 'END{print NR-1}'

END means, that the following block is executed after all lines are read and NR means the number of lines read so far.

Tags:

Wc