Sed command for find and replace matched word from file


Just replace the word from access.log: We’ve one file called access.log with below mention data/line.
Replacing the “five-5-success-factor.html” with “replace.html”.

access.log:
Hello tutorialbyexample, home page access by GET http://www.tutorialbyexample.com/ success HTTP 200
This is the success page of five success by POST http://www.tutorialbyexample.com/2015/09/five-5-success-factor.html HTTP 200
Hello tutorialbyexample, home page access by GET http://www.tutorialbyexample.com/ success HTTP 200
This is the success page of five success by POST http://www.tutorialbyexample.com/2015/09/five-5-success-factor.html HTTP 200
Hello tutorialbyexample, home page access by GET http://www.tutorialbyexample.com/
This is the success page of five success by POST http://www.tutorialbyexample.com/2015/09/five-5-success-factor.html
Hello tutorialbyexample, home page access by GET http://www.tutorialbyexample.com/


Command:
sed -i 's/five-5-success-factor.html/replace.html/g' access_200.log

Output in same file access.log:
Hello tutorialbyexample, home page access by GET http://www.tutorialbyexample.com/ success HTTP 200
This is the success page of five success by POST http://www.tutorialbyexample.com/2015/09/replace.html HTTP 200
Hello tutorialbyexample, home page access by GET http://www.tutorialbyexample.com/ success HTTP 200
This is the success page of five success by POST http://www.tutorialbyexample.com/2015/09/replace.html HTTP 200
Hello tutorialbyexample, home page access by GET http://www.tutorialbyexample.com/
This is the success page of five success by POST http://www.tutorialbyexample.com/2015/09/replace.html

Hello tutorialbyexample, home page access by GET http://www.tutorialbyexample.com/

No comments:

Post a Comment

Please provide your input, it will honer for me...