tags:

views:

294

answers:

5

I use Terminal in Mac with the following command:

   df -lak | grep File||disk02

what I want to use this script to get the header of df command (disk space) and the line with disk02 only. I think '|' is a char in grep as or logic. However, since I am using grep in Terminal, the char '|' also means pipe. Therefore I tried to use '||' to avoid piping, but it does not get what I want. Only the header with "File" is back.

Not sure how I can use this script command in Terminal?

+1  A: 

use awk

df -lak  | awk 'NR==1 || /disk02/'

Or

df -lak | grep -E "File|disk02"
ghostdog74
I can also use awk 'NR<3' for my case (first two lines are what I want). awk is new for me. Thanks!
David.Chu.ca
or awk '/File/ || /disk02/' as for my question in this post.
David.Chu.ca
be careful of other lines that have "File" in them. And yes, awk is more versatile than grep (and it does what grep does and more). Therefore its worthwhile learning it.
ghostdog74
+2  A: 
df -lak | grep "File\|disk02"
Sean Bright
+1  A: 
df -lak | grep -E '(^File|disk02)'

You can shorten grep -E to egrep.

Alok
+1  A: 
df -lak | grep -e File -e disk02
John Kugelman
A: 

Just display the mount points you're interested in!

df -lak /
Paul Hankin