LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   awk output (https://www.linuxquestions.org/questions/linux-newbie-8/awk-output-902836/)

linuxandtsm 09-13-2011 01:44 PM

awk output
 
Hi all,

i am trying to print columns 1 of df command with awk.
i used
Code:

df -h| awk '{ print $1 }'
but actual output from above command is including second column (size) of df command instead of just column1 1 (filesystem name). What is wrong in above command. Thanks in advance!

output:

Filesystem
/dev/mapper/vg00-lvol00
2031440
/dev/mapper/vg00-lvol04
10157368
/dev/mapper/vg00-lvol02
10157368
/dev/mapper/vg00-lvol03
10157368
/dev/mapper/vg00-lvol05
2031440
/dev/mapper/vg00-lvol07
16568712
/dev/mapper/vg00-lvol06
1015704

SL00b 09-13-2011 01:54 PM

No idea. Your command works just fine for me.

Are you sure you're entering the command correctly? Because df -h is supposed to turn the output into something human-readable, and your space looks like it's in 1K blocks (the default for df).

colucix 09-13-2011 01:57 PM

Look at the output of df -h: when the device name is too long, every entry is splitted over two lines, so that the first field in the even lines is the total size of the filesystem. To avoid that, use the -P option:
Code:

df -P | awk '{print $1}'

linuxandtsm 09-13-2011 02:01 PM

Thank you colucix,

it works now.

SL00b: typo, i used just df with no h option.


All times are GMT -5. The time now is 04:42 PM.