Home > Archive > AWK > March 2004 > Find word, replace line
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Find word, replace line
|
|
|
| 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é
| |
| Ted Davis 2004-03-19, 8:23 pm |
| On 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.
|
|
|
|
|