LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 09-20-2005, 05:03 AM   #1
dimsh
Member
 
Registered: Aug 2005
Distribution: Debian, Ubuntu, Fedora
Posts: 74

Rep: Reputation: 15
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.
 
Old 09-20-2005, 05:45 AM   #2
saneax
Member
 
Registered: Aug 2004
Distribution: Gentoo, Suse, Fedora, Debian
Posts: 86

Rep: Reputation: 15
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
 
Old 09-20-2005, 08:32 AM   #3
dimsh
Member
 
Registered: Aug 2005
Distribution: Debian, Ubuntu, Fedora
Posts: 74

Original Poster
Rep: Reputation: 15
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.
 
Old 09-20-2005, 11:13 PM   #4
saneax
Member
 
Registered: Aug 2004
Distribution: Gentoo, Suse, Fedora, Debian
Posts: 86

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

regards
 
Old 09-21-2005, 03:26 AM   #5
dimsh
Member
 
Registered: Aug 2005
Distribution: Debian, Ubuntu, Fedora
Posts: 74

Original Poster
Rep: Reputation: 15
thanks again.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
C++ text file line by line/each line to string/array Dimitris Programming 15 03-11-2008 08:22 AM
Python: find defined text string in a file, and replace the whole line Dark Carnival Programming 6 05-22-2007 06:02 AM
Substitute a string :) alaios Linux - General 3 06-12-2005 04:55 AM
Wierd String appended to end of line lel800 General 8 12-28-2004 03:55 PM
Converting a paragraph into a one-line string ganninu Linux - General 4 12-03-2003 07:50 AM


All times are GMT -5. The time now is 08:39 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration