LinuxQuestions.org
Visit Jeremy's Blog.
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 06-08-2011, 03:55 AM   #1
vanish78
LQ Newbie
 
Registered: May 2011
Posts: 13

Rep: Reputation: 9
Insert heading in awk


Hi,

I need to put headings ontop of the output of this awk script :

#!/bin/sh
PHP Code:
date
df
=`df -Pl | grep "^/dev" | awk '{print $6, int($2/1024+0.5) , int($4/1024+0.5) }' | sed "s/%//"`
echo 
"$df"


69550 55518
/tmp 7933 7375
/u01 49596 23227
/vote1 1024 742
/vote2 1024 742
/vote3 1024 742
/ocr 1024 506
/ocrmir 1024 506
/backup 204797 166291 
but this script errors out :

PHP Code:
#!/bin/sh
date
df
=`df -Pl | grep "^/dev" | awk 'BEGIN {print "MP TOTAL USED"
                                        print "-- ----- ----"}
'{print $6, int($2/1024+0.5) , int($4/1024+0.5) }' | sed "s/%//"
`
echo 
"$df"


Wed Jun  8 10:54:38 SAST 2011
-bashcommand substitutionline 7syntax error near unexpected token `('
-bash: command substitution: line 7: 
`'{print $6, int($2/1024+0.5) , int($4/1024+0.5) }' sed "s/%//"' 
Please help, thanks
 
Old 06-08-2011, 04:19 AM   #2
divyashree
Senior Member
 
Registered: Apr 2007
Location: Bangalore, India
Distribution: RHEL,SuSE,CentOS,Fedora,Ubuntu
Posts: 1,386

Rep: Reputation: 135Reputation: 135
Quote:
#!/bin/sh
df=`df -Pl | grep "^/dev" | awk 'BEGIN {print "MP TOTAL USED"
print "-- ----- ----"}
'{print $6, int($2/1024+0.5) , int($4/1024+0.5) }' | sed "s/%//"`
echo "$df"
The wrong is marked as red .. its the extra char you have. Remove that single quote.

Last edited by divyashree; 06-08-2011 at 04:56 AM.
 
1 members found this post helpful.
Old 06-08-2011, 08:19 AM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192
Probably a silly question, but is there a reason to put it all in a variable just to echo it all out again?

Also, df has the -h option to make human readable which nullifies the need for all the math.

So you could have just done:
Code:
df -Plh | awk 'BEGIN{print strftime();print "MP TOTAL USED\n-- ----- ----"}/^\/dev/{print $6,$2,$4}'
I would also probably prefer to use printf to get the spacing nicer too.

oh ... and I had no idea why the sed is even there??
 
  


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] Insert column with awk or sed between two columns captainentropy Linux - Newbie 9 11-27-2014 11:49 AM
awk search and insert? dyq Linux - Newbie 4 02-17-2010 12:04 AM
insert lines into a file after calculating where to insert xonar Programming 13 12-24-2009 04:37 AM
insert zero before single numbers using sed (or awk) chess Programming 10 10-22-2008 08:06 AM
Insert character by using sed/awk manish_meet_in Linux - General 3 04-05-2007 12:19 PM

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

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