Spot error with my awk command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Spot error with my awk command
# 1  
Old 08-24-2014
Spot error with my awk command

can any one identify why this command keeps resulting in 1, even though the string i'm searching for actually does not exist in the log?

Code:
awk 'BEGIN{count++} NR>220 && NR<=223 && /error/ && !/No.*such.*file.*or.*direfctory/ { count++ } END { print count }' /var/log/mail.log

i expected it to result in zero if the string is not found.

OS:

linux / aix
# 2  
Old 08-24-2014
You are incrementing count by one in the BEGIN block. In the END block you can use:
Code:
{ print count+0 }

This User Gave Thanks to pilnet101 For This Post:
# 3  
Old 08-24-2014
fixed. the solution was:

Code:
awk 'BEGIN{count=0} NR>220 && NR<=223 && /error/ && !/No.*such.*file.*or.*direfctory/ { count++ } END { print count }' /var/log/mail.log

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. Shell Programming and Scripting

Bash script with awk command ERROR

Hello im new here... Im trying to read file and create folders from words in it but i get this for loop error awk : line 3 : syntax error at or near for my code is.. #!/bin/bash begin for (( i=1;i<=5;i++)); do awk -v i=$i $0 { print $i } mkdir $i done {print $i} end {} i have... (7 Replies)
Discussion started by: boxstep
7 Replies

3. Shell Programming and Scripting

Getting syntax error while running awk command

Hello Gurus, I am firing the below command : df -g | grep -v var| awk '{ (if $4 > 90% ) print "Filesystem", $NF,"over sized";}' But I am getting the below error:- ====== syntax error The source line is 1. The error context is {if ($4 > >>> 90%) <<< awk: The... (9 Replies)
Discussion started by: pokhraj_d
9 Replies

4. UNIX for Dummies Questions & Answers

Can anyone help me to spot my mistake?

Hi there can anyone help me to spot my mistake and please explain why it appears My code : #!/usr/bin/gawk -f BEGIN { bytes =0} { temp=$(grep "datafeed\.php" | cut -d" " -f8) bytes += temp} END { printf "Number of bytes: %d\n", bytes } when I am running ./q411 an411 an411: ... (6 Replies)
Discussion started by: FUTURE_EINSTEIN
6 Replies

5. AIX

Error with new NIM SPOT

I have added our DR to NIM server and tried to create bosinstall image with smitty nim_bosinst command. But ended up with below error. warning: 0042-229 m_bos_inst: When installing a system using a mksysb as the source for the installation, the level of the SPOT used for the ... (3 Replies)
Discussion started by: newaix
3 Replies

6. Shell Programming and Scripting

awk command in script gives error while same awk command at prompt runs fine: Why?

Hello all, Here is what my bash script does: sums number columns, saves the tot in new column, outputs if tot >= threshold val: > cat getnon0file.sh #!/bin/bash this="getnon0file.sh" USAGE=$this" InFile="xyz.38" Min="0.05" # awk '{sum=0; for(n=2; n<=NF; n++){sum+=$n};... (4 Replies)
Discussion started by: catalys
4 Replies

7. Shell Programming and Scripting

error in awk command

ls filename*.txt | awk -F".Y" '$2 < $v_RUN_DT && $2 > $v_LOAD_DT'|awk ' NR==1' I am getting this error . Can somebody plz point me where is the problem. awk: 0602-562 Field $() is not correct. The input line number is 1. The source line number is 1. (16 Replies)
Discussion started by: RubinPat
16 Replies

8. AIX

SPOT requirement

Hey May be a dumb question Can I use a SPOT which is at 5.3 TL6 to boot an LPAR (with 5.3 TL8) in to maintenance mode? Will it work ? Is it mandatory that SPOT should be of same or higher version in such case? Bala (1 Reply)
Discussion started by: balaji_prk
1 Replies

9. Shell Programming and Scripting

Spot the difference

I posted earlier with a problem it's here, I have edited the script a little and it tells me once more that the end of line is unexpected and I'm really lost with this one, thanks for any help. The new version: #!/bin/sh case $# in 0) echo "Usage: enshar filename1 filename2 " >&2 ;;... (20 Replies)
Discussion started by: Dim-Wit
20 Replies

10. UNIX for Advanced & Expert Users

Spot

does somebody know about SPOT ?? any link about SPOT commands ? i ve made a mistake during configuration, :mad: then i ve started the system in Maintenance mode the only shell was SPOT. :eek: SPOT doesn t understand anything.... how do i work with SPOT ? thanks in advance Karine... :D (1 Reply)
Discussion started by: karine
1 Replies
Login or Register to Ask a Question