in reply to Replacing a search/not found pattern with a word

You got some great answers, but I'd rather ask you: What did you try? Did you look at the RegEx tutorial?
  • Comment on Re: Replacing a search/not found pattern with a word

Replies are listed 'Best First'.
Re^2: Replacing a search/not found pattern with a word
by pinpe (Novice) on Mar 24, 2008 at 21:29 UTC
    Hi, My apology of giving incomplete info. These were the commands I tried. Actually I want to search from every line of my standard output file the word "DOG" and if not found replaced the entire line with the word "Not Found!". I was confused if I will use a conditional statements or simply using search & replace method. And I end up with the solution below:
    #! c:\perl\bin\perl use Net::Telnet; @look=$net->cmd("cat $file | grep -i 'DOG' | awk 'NR==1' | nawk '{prin +t \$2}'); for $find (@look) { $find =~ s/(^DOG)/\uNot Found!/g; print "$find\n"; }
    I intentionally replaced my standard input file due work related terminologies. =) Tnx so much indeed for your ideas and tips. Br,