Code Comments
Programming Forum and web based access to our favorite programming groups.Hi, What AWK code should i use to: look for a certain word in a file, if found replace the whole line, else do nothing Thanks, fré
Post Follow-up to this messageOn 23 Feb 2004 03:53:24 -0800, griemer@chello.nl (fr?) wrote:
>Hi,
>What AWK code should i use to:
>
>look for a certain word in a file, if found replace the whole line, else do nothing
(assuming gawk)
In *ix
awk '{if(tolower($0) ~ /word/) $0 = "new line"; print $0}' file >
target
in Windows
awk "{if(tolower($0) ~ /word/) $0 = \"new line\"; print $0}" file >
target
That assumes that the word cannot appear as part of another word. If
it can and you know something about where it appears in the line, then
/ word / can be used if it is between two spaces, /word / if it is
the first word on the line, etc.
I'll leave the general solution of examining each of the fields
individually to someone else.
T.E.D. (tdavis@gearbox.maem.umr.edu)
SPAM filter: Messages to this address *must* contain "T.E.D."
somewhere in the body or they will be automatically rejected.
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.