awk in solaris


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk in solaris
# 1  
Old 10-01-2009
awk in solaris

Friends, I have a awk script which will calculate values for columns which is working fine in linux but failing in solaris.
here is my awk script

iostat -dt $INTERVAL $ITERATION | awk 'NR>4' | egrep -v "Linux|Device|Time|AM|PM|sda[0-9]" | awk '{if(/^$/){printf("%f \n"
,sum); sum=0}else{sum+=$2}}

but a similar thing is failing on solaris

here is the script on solaris

sar -d 2 2 | sed -n '/Average/!p;/Average/q;' | egrep -v "nfs[0-9]|device"|awk 'NR > 2 { if ($1 !~ /,.+/) print }'|

awk ' {if(/^$/){printf("%f \n"
,sum); sum=0}else{sum+=$2}} '
.

Can any one pls clarify why its failing in solaris and whats the remedy
# 2  
Old 10-01-2009
Hi.

You should use /usr/xpg4/bin/awk in Solaris.

Give that a try.
# 3  
Old 10-01-2009
And also, we are happy to help anybody but you you doesn't seem to accept our suggestions to improve your code. We have already suggested two times here and here that the way you construct your command is inefficient. Too much pipes.

I have the feeling that you are just looking for a solution. Not to improve your skills. We have a french saying that goes approximately like this:
"I you give a fish to a starving man, he will eat one day. If you learn him to fish, he will eat every day".
# 4  
Old 10-01-2009
Can u pls suggest how i can improve the code here. i wld love to incorporate this ideas to my code as i am still just learning the abc of awk.
# 5  
Old 10-01-2009
All you want to do can be done in one awk command. No need for cut, sed or grep as awk can do all that.

awk work on the <condition> {action} paradigm, so all your negative egrep can be given in the <condition> part. Also, if you want to skip a number of lines, just add a condition like NR>3, NR being the number of the line being processed. Have a look at your two other posts and try it yourself.

man awk is also the way to go to start with.

Your question has already been answered in your previous posts here and here. You just need to adjust the code a little bit.
# 6  
Old 10-01-2009
This is what i have trimmed down to

Code:
 sar -d 3 3 | awk 'NR>4 { if ($0 !~ /:/ && $1 !~ /,.+/) print}' | sed -n '/Average/!p;/Average/q;' | grep -v "nfs[0-9]"

. Now i need to compute the sum of the 2nd column like for fisrt iteration print the sun , then again print the sum for the 2nd iteration. pls guide me from here.

Last edited by vgersh99; 10-01-2009 at 11:22 AM.. Reason: code tags, PLEASE!
# 7  
Old 10-01-2009
To keep the forums high quality for all users, please take the time to format your posts correctly.

First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags [code] and [/code] by hand.)

Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.

Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.

Thank You.

The UNIX and Linux Forums

---------- Post updated at 10:24 AM ---------- Previous update was at 10:22 AM ----------

I'd strongly recommend reconsidering the 'trimmed down' version in favor of the previously mentioned alternate solutions - you seem to be missing the point and insisting on the 'sub-optimal' solution(s).
The purely awk-based solution(s) lends itself very easily to calculating of sum - you should be able to start with that and 'guide' yourself to the complete solution.
Good luck.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

awk command error in Solaris

I have the following code that works perfectly in Cygwin $ awk -F, ' BEGIN {months ="AP01"; months ="AP02"; months ="AP03"; months ="AP04"; months ="AP05"; months ="AP06"; months ="AP07"; months ="AP08"; months ="AP09"; months ="AP10"; months ="AP11"; months... (3 Replies)
Discussion started by: Raul_Rodriguez
3 Replies

2. UNIX for Dummies Questions & Answers

Converting HP-UX awk to Solaris

Hi, I am using awk in HP-UX to enter an encrypted entry of the password into /etc/passwd with success, this is the command I am using and it is working great. cat /tmp/passwd.gal.before|awk -F: -v gal_passwd="encrypted_password" '{OFS=":" ; print $1,gal_passwd,$3,$4,$5,$6,$7}' >... (3 Replies)
Discussion started by: galuzan
3 Replies

3. UNIX for Advanced & Expert Users

awk -v issue in Sun Solaris

Hi, awk -v is having issue in sun solaris, however the same works fine in HP Superdome. Pls advise what to do, while executing below command in SunOS. echo "this is saurabh"|awk -v a="SAURABH" '{ print a }' (2 Replies)
Discussion started by: sbaisakh
2 Replies

4. Shell Programming and Scripting

awk -F works on Linux, but not on Solaris

Hello, I found this command works on Linux: $ echo `uptime` | awk -F "load average: " '{ print $2 }' 1.60, 1.53, 1.46 but got error on Solaris: $ echo `uptime` | awk -F "load average: " '{ print $2 }' awk: syntax error near line 1 awk: bailing out near line 1 $ which awk... (2 Replies)
Discussion started by: seafan
2 Replies

5. Shell Programming and Scripting

awk script Error in Sun Solaris

Hi Friends, the below script has been through the errors in sun solaris. awk '/%s/{f=0 ;n++; print >(file="OUT_" n); close("OUT_" n-1)} f{ print > file}; /%s/{f=1}' $BASE_DIR/concat.TXT awk: syntax error near line 1 awk: bailing out near line 1 And ls $MERGE_DIR/*.R | awk ' { ... (2 Replies)
Discussion started by: krbala1985
2 Replies

6. Shell Programming and Scripting

System call using awk on Solaris

I'm brand new to awk and need your help. I want to be able to shut down my workstations when they become to hot (because we've lost our cooling). I found a really neat way to monitor the temperature of the system and a short, simple awk scipt to use with it: /usr/sbin/prtpicl -v -c... (2 Replies)
Discussion started by: natural
2 Replies

7. Shell Programming and Scripting

awk problem (Solaris vs Linux)

My overall goal is to parse a large log by date range - here's my code: awk '$0>=" This works fine with Linux but I get the following error with Solaris: awk: syntax error near line 1 awk: bailing out near line 1 Is there a known workaround for this problem? (1 Reply)
Discussion started by: bwatlington
1 Replies

8. Shell Programming and Scripting

awk and nawk on Solaris

Why do they do two different things? Like on one version of UNIX you can use awk, but tehn if you move to Solaris then awk becomes something crap and you need to use nawk instead! whY!?!?!?! (4 Replies)
Discussion started by: linuxkid
4 Replies

9. Shell Programming and Scripting

awk syntax for Solaris

Hi, Pass variable in SUN SOLARIS awk I have a file call text server1 10.0.0.2 When i use this awk command in Mac OS and Linux , everything works as expected. export HOSTNAME=server1 awk -v HOSTNAME=$HOSTNAME ' $1 ~ HOSTNAME { print $2 ; } ' text1 But when i entered the... (7 Replies)
Discussion started by: phamp008
7 Replies

10. Shell Programming and Scripting

awk on Solaris

Hi, we have a shell script like this .. # make sure all parameters are dealt with in upper case. for option in ${1} ${2} ${3} ${4} ${5} ${6} ${7} ${8} ${9} do option_name=`echo ${option} | awk -F \= '{print $1}'` if then SID=`echo ${option} | awk -F \= '{print $2}'` else ... (2 Replies)
Discussion started by: talashil
2 Replies
Login or Register to Ask a Question