LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Substitute String or line in a file (https://www.linuxquestions.org/questions/linux-newbie-8/substitute-string-or-line-in-a-file-365151/)

dimsh 09-20-2005 05:03 AM

Substitute String or line in a file
 
Hi all,

I have built a base configuration file (AWstats configuration file), I have to make a many customized configuration file from that file, and I need to write a script to do that.

the case is I need to substitute a certain lines in the base config file for every custom new file.

what command (or commands) should I user to search for the specified line, delete it , and put in my customized new line ?

Thanks for help.

saneax 09-20-2005 05:45 AM

Assuming the file you want to modify is abc.log
then ...
#>cat abc.log |perl -e ' foreach (<>) { s/SubtituteWhat/SubstituteWith/ig; print; } ' > abc_modified.log

dimsh 09-20-2005 08:32 AM

Thanks , this works :) :)
Great idea with perl saneax.
it substitute a particular sentence or matching string , it is useful and i will need it later

but for now,, how can I remove the complete line that contains the "Search for what" string ?

i need to remove the complete line by matching a small part of it , then i need to place another line instead of it.

saneax 09-20-2005 11:13 PM

#>cat abc.log |perl -e ' foreach (<> ) { s/.+SubtituteWhat.+/SubstituteWith/i; print; } ' > abc_modified.log

regards

dimsh 09-21-2005 03:26 AM

thanks again.


All times are GMT -5. The time now is 07:05 PM.