awk code not working in some HP versions


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk code not working in some HP versions
# 1  
Old 02-15-2010
awk code not working in some HP versions

Dear all,

Some one please help in solving this awk issue in HP.
The below code was working fine in HP version B.11.11 U 9000/800 but when the same was run B.11.31 U ia64 it failed. Smilie.
Code:
if awk 'BEGIN{if ('$var1' > 80); else exit 1}'
then
echo "Greater"
fi

# 2  
Old 02-15-2010
It just gives syntax errors on HPUX 11.11.
Have you copied the script correctly?
What is it designed to do?
# 3  
Old 02-15-2010
No change in the code..
But i think this server has some problem with the newline character ";". I tried putting "\" before ";", that too didnt work. Smilie
# 4  
Old 02-15-2010
Quote:
Originally Posted by engineer
No change in the code..
But i think this server has some problem with the newline character ";". I tried putting "\" before ";", that too didnt work. Smilie


---------- Post updated at 11:05 AM ---------- Previous update was at 11:05 AM ----------

Have you tried with

test $var1 -gt 80 && echo "greater"
# 5  
Old 02-15-2010
Try these examples
Code:
var1=81
awk -v var1=$var1 'BEGIN{ if (var1<81) { exit 1} else {exit} }' && echo "greater"
# or
[[ $var1 -gt 80 ]] && echo "greater"
var1=80
awk -v var1=$var1 'BEGIN{ if (var1<81) { exit 1} else {exit} }' && echo "greater"
[[ $var1 -gt 80 ]] && echo "greater"
echo "return status is $?, failure in this case"



You should have it as all shell - it is more effiicient than creating an awk child process for a simple compare. The shell approach also preserves the result of the compare in the $? variable so you can branch as needed. Just like the awk call.
# 6  
Old 02-16-2010
Thanks for all your help.

I knew the use of test and the script works but just wanted to know the reason for awk not working.
# 7  
Old 02-16-2010
The awk failed because it contained several syntax errors. When you study jim mcnamara's suggestions you will notice that space characters and the correct use of braces are paramount.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

"SQLPLUS -S " is not working in one environment where same code is working in another

"SQLPLUS -S " is not working in one environment where same code is working in another getting below error =================================== SQL*Plus: Release 11.2.0.3.0 Production Copyright (c) 1982, 2011, Oracle. All rights reserved. Use SQL*Plus to execute SQL, PL/SQL and SQL*Plus... (1 Reply)
Discussion started by: yogendra.barode
1 Replies

2. Shell Programming and Scripting

Why this code is not working?

Hello, I'm working with factorial code, and thought to do multiple parenthesis arithmetic expression. So, I got the code working with the following code: read -p "Enter number: " n d=1 cnt1=$n cnt2=$cnt1 while do cnt2=$(($cnt2 - 1)) #eq1 cnt1=$(($cnt1 * ($cnt2))) #eq2 done... (5 Replies)
Discussion started by: wolfrose
5 Replies

3. Shell Programming and Scripting

Awk: System command not working in awk

Hi, I have around 10 files in a folder in which I want to change the file format from tab(\t) to pipe(|) with some changes in the fields as well. Below is the code, while tmp file is getting generated but move command is not working, please help Following is the code awk -F"\t" '{print... (2 Replies)
Discussion started by: siramitsharma
2 Replies

4. Shell Programming and Scripting

How to make this code working?

Hi Gurus, I wrote a simple code, but it doesn't work, can body help me to fix the issue. awk -F',' 'BEGIN{n=0}{ NR == FNR {fname;next} { if ($3==fname) n=1 } END{if n==0} }' tmpsrc srcfile.txt Thanks in advance (4 Replies)
Discussion started by: ken6503
4 Replies

5. Shell Programming and Scripting

Getline not working in awk

hi, i am trying to parse a file in awk to generate a output to be written in a file depeding upon some condition. below is the code Content of file1 919873741577,9131638459976206,20130715150109,S,919811000214,2A65,405899136999995... (10 Replies)
Discussion started by: siramitsharma
10 Replies

6. Shell Programming and Scripting

awk help : if then else not working!

Hi All, This code is not working when trying with "else" : Am I missing something, uptime|sed 's/,/ /g' | awk '{ if ($10 >1) { print ( " :: UPTIME GT 1 : ALERT" )} ;else print "OK" }' Getting this error: syntax error The source line is 1. The error context is { if... (4 Replies)
Discussion started by: rveri
4 Replies

7. Shell Programming and Scripting

Concatenation in awk not working

Hello I want to achieve the following. However the concatenation is not working mv `ls -ltr *myfile*.log|awk '{print $9}'` `ls -ltr *myfile*.log|awk '{print `date +'%d%m%y%k%M%S'` $9}'` I tried awk '{x=`date +'%d%m%y%k%M%S'` print $x "" $9}' awk '{x=`date +'%d%m%y%k%M%S'`... (2 Replies)
Discussion started by: Chetanz
2 Replies

8. UNIX for Advanced & Expert Users

Awk expressions working & not working

Hi, Putting across a few awk expressions. Apart from the last, all of them are working. echo a/b/c | awk -F'/b/c$' '{print $1}' a echo a/b/c++ | awk -F'/b/c++' '{print $1}' a echo a/b/c++ | awk -F'/b/c++$' '{print $1}' a/b/c++ Request thoughts on why putting a '$' post double ++... (12 Replies)
Discussion started by: vibhor_agarwali
12 Replies

9. Shell Programming and Scripting

making code compatible to previous bash versions

First let me explain the scenario I have tywo files as usual file1.txt (it has n rows and 8 columns) $1 $2 $3 $4 $5 $6 $7 $8 Code: 1234567|iufgt|iuoy|iout|white |black |red |90879 1234567|iufgt|iuoy|iout|green |pink |blue |90879... (3 Replies)
Discussion started by: s.deepak
3 Replies

10. Shell Programming and Scripting

awk not working for me.

Hi All, I have a server.xml file which looks something like. <Connector port="8443" maxHttpHeaderSize="8192" maxThreads="150" minSpareThreads="25" maxSpareThreads="75" enableLookups="false" disableUploadTimeout="true" acceptCount="100"... (2 Replies)
Discussion started by: nua7
2 Replies
Login or Register to Ask a Question