Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
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é

Report this thread to moderator Post Follow-up to this message
Old Post
fr?
03-20-04 01:23 AM


Re: Find word, replace line
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.

Report this thread to moderator Post Follow-up to this message
Old Post
Ted Davis
03-20-04 01:23 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

AWK archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 04:55 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.