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, 02:37 AM   #1
ust
Senior Member
 
Registered: Mar 2003
Location: fasdf
Distribution: Debian / Suse /RHEL
Posts: 1,130

Rep: Reputation: 31
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, 04: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, 11:23 AM   #3
makyo
Member
 
Registered: Aug 2006
Location: Saint Paul, MN, USA
Distribution: {Free,Open}BSD, CentOS, Debian, Fedora, Solaris, SuSE
Posts: 735

Rep: Reputation: 76
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, 10:11 PM   #4
ust
Senior Member
 
Registered: Mar 2003
Location: fasdf
Distribution: Debian / Suse /RHEL
Posts: 1,130

Original Poster
Rep: Reputation: 31
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, 10: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, 02:18 AM   #6
H_TeXMeX_H
LQ Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

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

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

All times are GMT -5. The time now is 07:01 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