LinuxQuestions.org
Register a domain and help support LQ
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 03-27-2014, 01:09 PM   #1
raosr020
LQ Newbie
 
Registered: Nov 2012
Posts: 17

Rep: Reputation: Disabled
Smile Commenting a line matched with a specific string in a file


Hi,

I would like to comment a line that matched a string "sreenivas" in a file without opening it.

Thanks in advance.

Regards,
Sreenivas
 
Old 03-27-2014, 01:27 PM   #2
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,094

Rep: Reputation: 1515Reputation: 1515Reputation: 1515Reputation: 1515Reputation: 1515Reputation: 1515Reputation: 1515Reputation: 1515Reputation: 1515Reputation: 1515Reputation: 1515
Code:
sed -i '/sreenivas/s/^/#/g' somefile.txt

# GNU sed version 4.2.1
This is really a simple Google Search away. You should try looking things up before asking about them.
 
1 members found this post helpful.
Old 03-27-2014, 03:36 PM   #3
joe_2000
Member
 
Registered: Jul 2012
Location: Aachen, Germany
Distribution: Void, Debian
Posts: 812

Rep: Reputation: 216Reputation: 216Reputation: 216
Code:
awk '/screenivas/ { print "#", $0 } !/screenivas/ ' inputfile.txt  >  outputfile.txt

Last edited by joe_2000; 03-27-2014 at 03:37 PM. Reason: added redirect to outputfile
 
1 members found this post helpful.
  


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
[SOLVED] delete a matched line from the file+shell script novicunix Programming 13 02-01-2013 09:37 AM
How to grep string in tar.gz file with matched filenames? beeth2006 Linux - Newbie 3 09-29-2011 11:00 AM
read string after specific string from a text file using C++ programing language badwl24 Programming 5 10-08-2009 06:41 AM
script for deleting matched line of a file from another file $Arsh Linux - Newbie 2 09-03-2009 08:38 AM


All times are GMT -5. The time now is 10:03 AM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration