LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
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, 04: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, 05:19 AM   #2
divyashree
Senior Member
 
Registered: Apr 2007
Location: bbsr,orissa,India
Distribution: RHEL5 ,RHEL4,CENT OS5,FEDORA,UBUNTU
Posts: 1,362

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 05:56 AM.
 
1 members found this post helpful.
Old 06-08-2011, 09:19 AM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,243

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
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


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


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