Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

If pattern is not found 2

Status
Not open for further replies.

frangac

Technical User
Feb 8, 2004
163
ZA
Hi,

Below is my code which the output I receive is not what I expect. What I need help in is when
/[a-z]:/ is not found print a mesg and then exit or else if pattern is found, print certain columns as required.


awk '{if(!~/:/){
print "No Errors were Found for `date +'%Y%m%d'`"
}
else
{
printf "%s %s\n", $1,$2
}
}' file > output filename

sample file

APAU_DATETIME APAU_USER_NAME APAU_EXTRAINFO

-------------------------- ------------------------------ ---------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------
Jul 11 2005 7:19AM Jack rrr:05 Correct: 2

(1 row affected)

and

APAU_DATETIME APAU_USER_NAME APAU_EXTRAINFO

-------------------------- ------------------------------ ---------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------


(0 row affected)

Many Thanks
Chris
 
Hi

I do not really understand your problem. If was only the syntax, then this works for me :

Code:
awk '
BEGIN {ORS=""}
{
  if ($0!~/[a-z]:/) { print "No Errors were Found for "; system("date +%Y%m%d"); }
  else { printf "%s %s\n", $1,$2; }
}
' file > output filename

Feherke.
 
Hi Feherke,

Thanks for your responce. I get the same output as what you get with your code. I have managed to resolve it

awk ' /[a-z]:/{
++a
printf "%s %s \n", $1,$2
}
END{if(!a){
printf "No Errors were Corrected/commited for $DATE"
}
}' file1 > output Filename


Many Thanks Once Again
Chris
 
Code:
/[a-z]:/ { print $1,$2; e++ }
END { if (!e) print "No errors." }
 
Hi Futurelet,

Short, sweet and to the point(perfect).

Many Thanks
Chris

 
Hi Futurelet,

Short, sweet and to the point(perfect).

Many Thanks
Chris

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top