LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-13-2011, 01:44 PM   #1
linuxandtsm
Member
 
Registered: May 2011
Posts: 194

Rep: Reputation: Disabled
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
 
Old 09-13-2011, 01:54 PM   #2
SL00b
Member
 
Registered: Feb 2011
Location: LA, US
Distribution: SLES
Posts: 375

Rep: Reputation: 112Reputation: 112
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).
 
Old 09-13-2011, 01:57 PM   #3
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
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}'
 
1 members found this post helpful.
Old 09-13-2011, 02:01 PM   #4
linuxandtsm
Member
 
Registered: May 2011
Posts: 194

Original Poster
Rep: Reputation: Disabled
Thank you colucix,

it works now.

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


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Bash; awk or sed output to variable: how keep newline at end of each output line porphyry5 Programming 3 06-10-2011 05:50 PM
output formatting with awk. pinga123 Programming 4 11-26-2010 07:56 AM
awk does not > output Alkass Programming 4 04-25-2010 05:10 PM
Awk Output kalyanofb Programming 4 02-02-2007 02:23 AM
Awk output Trouble fooforon Programming 6 04-12-2004 07:14 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:50 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration