I am trying to:

Print the output of the command "df -h" (in macOS),but only with /dev/disk* as ouptut. I used the following command:

df -h|awk -F"\t" '/\/[d-v]{3}\/[a-z]{4}[0-9]{1}[s-t]{1}[0-9]{1}/{print}'|uniq -c

Output from the command

The original output of command df-h contains the column headers such as "FileSystem ,size,used etc."I trying to achieve the same via the code.


you almost manage it

awk 'NR==1 { print ; } /your code/ {print ;}


  • NR==1 { print ;} will instruct awk to print first line (Number of Record == 1 )
df -h|awk 'NR==1 || /\/dev\/disk/ {print}'|uniq -c

This prints the first record (denoted by NR, which is the header) and then any lines matching /dev/disk. The || means "or".

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.