12-27-2013
Quote:
Originally Posted by
SkySmart
thank you. the shell if statements dont handle numbers like this "73.39", which is why i decided to use awk. its either awk or perl. and i personally dont like perl.
i'll retry with the closing brackets. dont know how i missed that. and by the way, yes, i am including this in a while loop. the original awk program i wrote didnt' have the breaks in it. but since it look like awk was running all four conditions instead of just one, i decided to put the break in there to try to force it break out of the first condition it matches.
Some shell if statements don't handle floating point comparisons. If you have a 1993 or later
ksh, it is perfectly capable of handling double precision floating point arithmetic in arithmetic expressions and in numeric comparisons.
This User Gave Thanks to Don Cragun For This Post:
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hello,
Can you explain why in the first 2 commands the awk does not print anything? Is it looking of a specific format ?
Thanks.
$ echo 12a3 | awk '($1>=2) {print $1}' # prints nothing
$ echo 123a | awk '($1>=2) {print $1}' # prints nothing
$ echo a123 | awk '($1>=2) {print $1}'
a123... (1 Reply)
Discussion started by: majormark
1 Replies
2. Shell Programming and Scripting
how can i specify more than 1 consition in the following AWK statament??
i.e. if $2 is ABCD and $3 is MNOP and $4 is KLPM
similarly for OR
#!/bin/ksh
awk -F '' ' $2 == "ABCD" { print $2, $3;}' file.xml (2 Replies)
Discussion started by: skyineyes
2 Replies
3. Shell Programming and Scripting
Hi,
Does any one know how to avoid the scenario where awk ignores the fields having only spaces or empty fields?
for instance,
Data: "a","b","c","d",""," "
code:
awk -F, '{ print NF }' File
the output I get is 4 instead of 6 do you know how to avoid this? (6 Replies)
Discussion started by: ahmedwaseem2000
6 Replies
4. Shell Programming and Scripting
Hi Everyone,
# cat 1
1;2;3;4;5;6
1;2;3;4;5;
# awk -F ";" '$5 == "5"' 1
1;2;3;4;5;6
1;2;3;4;5;
but the output is should be just "1;2;3;4;5;6" means 1st condition: $5 is 5; 2nd condition: $6 is not empty, please advice. Thanks (2 Replies)
Discussion started by: jimmy_y
2 Replies
5. Shell Programming and Scripting
Input File1
0BB2 2A11 Split,FriApr80625,1507_7RAID5
0BF6 2829 Synchronized,FriJan140653,1507_7RAID5
0BF6 282A Split,FriApr80625,1507_7RAID5
0C7C 199E Synchronized,FriJan140653,1507_7RAID5
0C7C 1BCC Split,FriApr80625,1507_7RAID5
0DCA 0A9B ... (12 Replies)
Discussion started by: greycells
12 Replies
6. Shell Programming and Scripting
Hi there, here is my command
ssh host.local "/path/to/my/perscript/hostconfig.pl -s $HOST -d |awk '{if (\$4 > 120)print \"My error message\";exit}{s=0; for (i=1; i<=NF; i++) s++; if(s == 13) print \$3}'"
The problem is if conditional 1 is met (i.e $4 > 120), i don't see "My error message", the... (5 Replies)
Discussion started by: urello
5 Replies
7. Shell Programming and Scripting
Hi All,
I have a file with below contents.
"en2"/10.185.81.0:cluster_interconnect,"en5"/10.185.81.0:cluster_interconnect,"en6"/169.181.146.0:public
I want to take the interface name from the file and convert it as ipaddress using ifconfig command get the output like below
en6 ->... (2 Replies)
Discussion started by: kamauv234
2 Replies
8. Shell Programming and Scripting
I'm having a problem pulling UID's from data. The data outputs a user's UID in one of three ways:
1. Error User user_name already assigned with <UID>
2. Success <UID> reserved for user_name
3. <a load of crap because there was a db failure yet somehow the UID is still in there>
I typically... (5 Replies)
Discussion started by: MaindotC
5 Replies
9. Shell Programming and Scripting
Hello Friends,
I need to find some CDRs in production servers whose 1st field value and 2nd field value = 1 and 11th looks like 45.123... where there are more than 3 digits after comma.so i wrote a one liner, something like below but does not work, however when i used first and second conditions... (8 Replies)
Discussion started by: EAGL€
8 Replies
10. UNIX for Dummies Questions & Answers
hello gurus,
I want to use an associative array from a file to populate a field of another file, by matching several columns in order of priority. If the first column matches, then i dont want to match $2. Similarly I only want to match $3 when $1 and $2 are not in associative array.
For the... (6 Replies)
Discussion started by: ritakadm
6 Replies
LEARN ABOUT OPENSOLARIS
igawk
IGAWK(1) Utility Commands IGAWK(1)
NAME
igawk - gawk with include files
SYNOPSIS
igawk [ all gawk options ] -f program-file [ -- ] file ...
igawk [ all gawk options ] [ -- ] program-text file ...
DESCRIPTION
Igawk is a simple shell script that adds the ability to have ``include files'' to gawk(1).
AWK programs for igawk are the same as for gawk, except that, in addition, you may have lines like
@include getopt.awk
in your program to include the file getopt.awk from either the current directory or one of the other directories in the search path.
OPTIONS
See gawk(1) for a full description of the AWK language and the options that gawk supports.
EXAMPLES
cat << EOF > test.awk
@include getopt.awk
BEGIN {
while (getopt(ARGC, ARGV, "am:q") != -1)
...
}
EOF
igawk -f test.awk
SEE ALSO
gawk(1)
Effective AWK Programming, Edition 1.0, published by the Free Software Foundation, 1995.
AUTHOR
Arnold Robbins (arnold@skeeve.com).
ATTRIBUTES
See attributes(5) for descriptions of the following attributes:
+--------------------+-----------------+
| ATTRIBUTE TYPE | ATTRIBUTE VALUE |
+--------------------+-----------------+
|Availability | SUNWgawk |
+--------------------+-----------------+
|Interface Stability | Volatile |
+--------------------+-----------------+
NOTES
Source for gawk is available on http://opensolaris.org.
Free Software Foundation Nov 3 1999 IGAWK(1)