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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
03-14-2009, 07:41 AM
|
#1
|
|
LQ Newbie
Registered: Jan 2009
Posts: 12
Rep:
|
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
|
|
|
|
03-14-2009, 11:36 AM
|
#2
|
|
Guru
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 12,003
|
Quote:
Originally Posted by suran
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.
|
|
|
|
03-14-2009, 09:03 PM
|
#3
|
|
Senior Member
Registered: Aug 2006
Posts: 2,695
|
you just simply need to arrange your columns's position
Code:
df -lh | awk '{ print $1,$6,$4 ...}
|
|
|
|
03-15-2009, 02:53 PM
|
#4
|
|
LQ Newbie
Registered: Jan 2009
Posts: 12
Original Poster
Rep:
|
aww man!! I feel stupid! rearranging columns in awk was one of the first things i learned on unix!
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 05:55 AM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|