LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 03-14-2009, 07:41 AM   #1
suran
LQ Newbie
 
Registered: Jan 2009
Posts: 14

Rep: Reputation: 0
How to print data in rows and columns


Hi,

I'm working a script to give system information. And i'd like to do the following

I want to be able to print values into rows and columns, for example

have

F1=1
F2=6
F3=2
F4=3
F5=4

df -lh | awk '{print $'$F1', $'$F2', $'$F3', $'$F4', $'$F5'}' \
|while read FIRST SECOND THIRD FOURTH FIFTH
do
echo "Filesystem = ${FIRST}"
echo "Mountpoint = $(SECOND}"
echo "Capacity = ${THIRD}"
echo "Used = ${FOURTH}"
echo "Available = ${FIFTH}"
done


problem is this prints the data as follows

Filesystem = /dev/sda1
Mountpoint = /home
Capacity = 25G
Used = 1G
Avail = 24G

now if there are lots of file sytems then the output looks a bit shoddy.... what do i need to do to print the data like so:

Filesystem Mountpoint Capacity Used Avail
/dev/sda1 / 25G 1G 24G



Thanks
 
Old 03-14-2009, 11:36 AM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,634

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by suran View Post
Hi,

I'm working a script to give system information. And i'd like to do the following

I want to be able to print values into rows and columns, for example

have

F1=1
F2=6
F3=2
F4=3
F5=4

df -lh | awk '{print $'$F1', $'$F2', $'$F3', $'$F4', $'$F5'}' \
|while read FIRST SECOND THIRD FOURTH FIFTH
do
echo "Filesystem = ${FIRST}"
echo "Mountpoint = $(SECOND}"
echo "Capacity = ${THIRD}"
echo "Used = ${FOURTH}"
echo "Available = ${FIFTH}"
done


problem is this prints the data as follows

Filesystem = /dev/sda1
Mountpoint = /home
Capacity = 25G
Used = 1G
Avail = 24G

now if there are lots of file sytems then the output looks a bit shoddy.... what do i need to do to print the data like so:

Filesystem Mountpoint Capacity Used Avail
/dev/sda1 / 25G 1G 24G

Thanks
How about putting it all on the same line???

echo "Mountpoint = $(SECOND)\t$(THIRD)\t$(FOURTH)\t$(FIFTH)"

The '\t's are tabs, if I remember correctly.
 
Old 03-14-2009, 09:03 PM   #3
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
you just simply need to arrange your columns's position
Code:
df -lh | awk '{ print $1,$6,$4 ...}
 
Old 03-15-2009, 02:53 PM   #4
suran
LQ Newbie
 
Registered: Jan 2009
Posts: 14

Original Poster
Rep: Reputation: 0
aww man!! I feel stupid! rearranging columns in awk was one of the first things i learned on unix!
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
data with same number of rows and coloumns C/C++ fs11 Programming 2 04-29-2008 10:17 PM
Parsing rows and column data from a file using perl dav_y2k Programming 1 10-08-2006 11:57 AM
text data conversion: rows into columns frankie_DJ Programming 6 06-03-2006 06:43 AM
columns & rows Ammad Linux - General 1 08-08-2005 04:02 AM
rows and columns digitalgravy Linux - General 2 03-16-2004 06:47 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 12:41 PM.

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