1

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.

2 Answers 2

1

you almost manage it

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

where

  • NR==1 { print ;} will instruct awk to print first line (Number of Record == 1 )
0
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".

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .