LinuxQuestions.org
Review your favorite Linux distribution.
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 10-27-2008, 03:37 AM   #1
ust
Senior Member
 
Registered: Mar 2003
Location: fasdf
Distribution: Debian / Suse /RHEL
Posts: 1,130

Rep: Reputation: 30
make the output tidy


I use the command df awk '{print $1 " " $2 " "$3 }' , the output is not tidy , there are different space in each row ,

/dev/sda7 2016016 353856
/dev/sda13 50394996 220080
/dev/sda3 15116868 6611780
/dev/sda8 2016016 1508268


can advise how to make it more tidy as below ?

/dev/sda7 2016016 353856
/dev/sda13 50394996 220080
/dev/sda3 15116868 6611780
/dev/sda8 2016016 1508268
 
Old 10-27-2008, 05:16 AM   #2
pinniped
Senior Member
 
Registered: May 2008
Location: planet earth
Distribution: Debian
Posts: 1,732

Rep: Reputation: 50
You can try adding tab separators (\t) in the output rather than ordinary spaces.
I haven't done much scripting in years, but look at the manual; there may be a way to specify the column to tab to, which would make it easier to pretty-print.
 
Old 10-27-2008, 12:23 PM   #3
makyo
Member
 
Registered: Aug 2006
Location: Saint Paul, MN, USA
Distribution: {Free,Open}BSD, CentOS, Debian, Fedora, Solaris, SuSE
Posts: 727

Rep: Reputation: 74
Hi.

It would help if you would use the CODE tags to display data and code. See the sig below for instructions.

It would appear that you are seeking something to align fields in files. If so, then the best field alignment tool I have seen is the perl script at http://www.cs.indiana.edu/~kinzler/align/

I find it to be valuable ... cheers, makyo
 
Old 10-27-2008, 11:11 PM   #4
ust
Senior Member
 
Registered: Mar 2003
Location: fasdf
Distribution: Debian / Suse /RHEL
Posts: 1,130

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by pinniped View Post
You can try adding tab separators (\t) in the output rather than ordinary spaces.
I haven't done much scripting in years, but look at the manual; there may be a way to specify the column to tab to, which would make it easier to pretty-print.


sorry to my fool ,

I try to use \t to my command ( in the middile , end of my command ) , but still not work , can advise how to use it ? thx



df | awk '{print $1 " " $2 " "$3 }' \t
 
Old 10-27-2008, 11:22 PM   #5
AuroraCA
Member
 
Registered: Jul 2008
Location: Northern CA USA
Distribution: Ubuntu, Slackware, Gentoo, Fedora, Red Hat, Puppy Linux
Posts: 370

Rep: Reputation: 35
Try putting the tabs between the variables in the print statement.

Code:
df | awk '{print $1 "\t" $2 "\t" $3 }'
 
Old 10-28-2008, 03:18 AM   #6
H_TeXMeX_H
LQ Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1285Reputation: 1285Reputation: 1285Reputation: 1285Reputation: 1285Reputation: 1285Reputation: 1285Reputation: 1285Reputation: 1285
Remember that with awk you can also use printf() C function which is way more powerful than print, for example:
Code:
df | awk '{ printf("%-10s %10d %10d\n",$1,$2,$3) }'
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Tidy exit in C mykaitch Programming 11 03-23-2007 04:18 AM
DISCUSSION: Tidy Up With HTML Tidy jeremy LinuxAnswers Discussion 0 10-10-2005 08:25 PM
the output is not tidy ust Linux - Software 1 10-04-2004 02:30 AM
Make output spotslayer Linux - Software 0 08-10-2004 08:11 PM
Look the output of: make dep && make clean bzImage modules modules_install Hell-Shooter Linux - General 2 06-05-2004 06:05 AM


All times are GMT -5. The time now is 11:02 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration