awk giving different outputs each time


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk giving different outputs each time
# 1  
Old 04-12-2013
awk giving different outputs each time

I have a strange issue.

Code:
(awk '$3 == "nfs" { cnt++ }; END { print cnt }' /etc/fstab)

This is giving different count each time.


To test this, tried the one here
Code:
-bash-3.2$ awk '/nfs/{print $2}' /etc/fstab | wc -l
151
-bash-3.2$ awk '/nfs/{print $2}' /etc/fstab | wc -l
145
-bash-3.2$ awk '/nfs/{print $2}' /etc/fstab | wc -l
150

checking the output, it has all wired outputs each time, since command was searching for "nfs", it is giving all non matched strings. output were always different.

do
/boot
/tmp
/var
none
/dev/pts

The same script is working on all other 100+ machines, only one machine is showing the wired stuff.

its not an issue with file type, its happening with every file

Code:
552
-bash-3.2$ awk '/bash/{print $1}' /etc/passwd | wc -l
556
-bash-3.2$ awk '/bash/{print $1}' /etc/passwd | wc -l
552

-bash-3.2$ awk '/nfs/{print $1}' /proc/mounts | wc -l
147
-bash-3.2$ awk '/nfs/{print $1}' /proc/mounts | wc -l
145

any ideas/thoughts ?
# 2  
Old 04-12-2013
Yes, that seems pretty strange. I assume when you use grep in a similar way to how you are using awk, to count the number of matching lines, there is no problem? In other words, does grep always give the same count of /etc/passwd lines with the word "bash"? And do you know for sure what the "right" answers are in each case? Does awk usually give the right answer, or wrong answer?

Have you tried "which awk" and investigating the file that it reports? Kind of a reality check.
# 3  
Old 04-12-2013
grep is correct, thats my work around for the time being..

this issue looks really wierd, I even tried to reinstall the gawk pkg, still issue persists

/bin/awk which is linked from /bin/gawk


The thing is awk give right sometimes, sometimes the same command even displays non matched strings.

say here in the fstab, its giving


do
/boot
/tmp
/var
none
/dev/pts

which does not have an "nfs" keyword
# 4  
Old 04-12-2013
Have you checked the md5sum on gawk executable, compared with that on other machines? Since you re-installed, I'm just clutching at straws.

IMO, you really need to figure out why this is happening. We all know from many years of experience that there is no "magic". There is always an explanation, and some funky behavior like this has to be diagnosed and fixed. There is something weird going on, awk printing lines without a match. Logically, either the input file is changing (but would not explain awk reporting non-matching lines), or awk is damaged (seems impossible since you re-installed), or a hardware problem (?), or something else (no guess). I hope that machine is not doing anything mission-critical. Smilie If you have 100+ machines, and awk continues to malfunction, maybe this machine should be sold off?

What happens if you copy /etc/fstab to your user directory, and run awk as the user instead of as root? Or vice versa? Again, just clutching at straws.
# 5  
Old 04-12-2013
hanson44,

Quote:
What happens if you copy /etc/fstab to your user directory, and run awk as the user instead of as root? Or vice versa? Again, just clutching at straws.
all giving wrong outputs, tried almost all things what you mentioned already.

but yea I will track this down, may need some more time
# 6  
Old 04-12-2013
That is really strange. I have some other experts on the forum, probably smarter than me, have some ideas.
# 7  
Old 04-12-2013
If it's only happening on one machine, I would suspect problems like disk or memory errors.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Printing awk outputs

Hello All, I have the following command which works partially: gzcat *2016-03-25_*gz | gawk -F"|" ' BEGIN{format = "%-10s %-13s %-17s %-35s\n"; printf format, "EVENT_TYPE","RESPONSE_CODE","INTERNAL_ERR_CODE","FLOWNAME"; printf format, "----------", "-------------", "-----------------",... (6 Replies)
Discussion started by: EAGL€
6 Replies

2. Web Development

ReWrite rule giving a hard time.

Hi all, I am trying to find a rewrite rule that can help me with the following situation. So I am currently on a page which has a URL: http://www.test.mobile.com/#!/shop/phones/max-plus/features/ Now when I hover over a certain link, I can see that it will goto: <a... (0 Replies)
Discussion started by: Junaid Subhani
0 Replies

3. UNIX for Dummies Questions & Answers

VxWorks RTC time giving wrong value at random times

I am seeing a scenario where in if the TIMEZONE environment variable value is set to nothing i.e. putenv "TIMEZONE=" the hardware clock is +1 to software clock.Pasted below the results displayed: -> envShow (global environment) 0: TSC_TIME_FROM_RESET=420150.971529 seconds 1:... (0 Replies)
Discussion started by: snehavb
0 Replies

4. Shell Programming and Scripting

How to prvenent giving password run time in schell scripting?

Hi I'm copying around 20 vi files from solaris server-A to server-B using 'scp' command.I have included all 20 scp commands in one shell script. Proplem is, while executing each scp command its prompting for my NIS password of server A. Please see below How to get rid of password prompt.??? (1 Reply)
Discussion started by: buzzme
1 Replies

5. Shell Programming and Scripting

Time outputs of wget command

Hello friends, I've been working on a solaris server, I need to test responses of a web service using WGET command, if the response is successful, how quick it is etc. I have scirpt like this, I modified it, i try to redirect the output of time command to total.txt but i couldn't manage, i... (4 Replies)
Discussion started by: EAGL€
4 Replies

6. UNIX for Dummies Questions & Answers

AWK - Different outputs *Question*

I'm having a small issue with AWK: I run this in PUTTY: awk 'BEGIN{FS=","}NR==FNR{A=$1;next}{if (A==$1) print $0}' FILE1 FILE2 And it gives me the output that I expect. I wanted to create a file.awk file that i could just run instead of typing this out all the time. But its not giving my... (1 Reply)
Discussion started by: WongSifu
1 Replies

7. Shell Programming and Scripting

Array in awk outputs multiple values

Disclaimer: OP is 100% Awk beginner. I use this code on ASCII files I need to report against. awk 'BEGIN { tokens = 0 tokens = 0 tokens = 0 } { for (token in tokens) { if ($1 == token){print $0; tokens++;}}} END {for (token in tokens){ if( tokens ==... (1 Reply)
Discussion started by: alan
1 Replies

8. UNIX for Dummies Questions & Answers

machine hangs for some time after giving password.

Hi I m trying to take a console of linux machine using putty. Whenever i connect to the machine and give password details to log into the machine it hangs for some time and then it allow the login. I m totally clueless why it is happening suddenly . ---------- Post updated at 01:14 AM... (1 Reply)
Discussion started by: pinga123
1 Replies

9. Shell Programming and Scripting

How to store multiple outputs from an awk command?

x=`echo $line | awk -F "|" '{print $1;print NR}'` How will I get the 2 return values ($1 and NR) from awk to variables? (4 Replies)
Discussion started by: tene
4 Replies

10. Shell Programming and Scripting

Printing outputs using awk.

I have a output of a command like this. the command is : bdf|sed '/^e/d'|awk '{print$2/1048576}' output : 0 0.515625 0.481979 2 2 2 7.8125 4 2 0.488281 7.8125 3.90625 4 1.95312 1 0.488281 (4 Replies)
Discussion started by: Krrishv
4 Replies
Login or Register to Ask a Question