LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices



Reply
 
Search this Thread
Old 05-29-2005, 07:38 PM   #1
DediPlace
LQ Newbie
 
Registered: May 2005
Posts: 9

Rep: Reputation: 0
How to search and replace a text using grep


Hi,

I can't remember, I know I can search a string from all the files in one directory and replace the string also using grep...

What is the command again?

I want to change the occurance of text "ns1" to "ns".

Thanks
 
Old 05-29-2005, 07:40 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,005
Blog Entries: 11

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
You can't ... grep only greps, no replacements.


sed is what you're after

sed -i 's/ns1/ns/g' file



Cheers,
Tink
 
Old 05-29-2005, 07:47 PM   #3
DediPlace
LQ Newbie
 
Registered: May 2005
Posts: 9

Original Poster
Rep: Reputation: 0
Thanks very much! It works perfectly.

Regards,
 
  


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 On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Script to search and replace in text file - kinda... jeffreybluml Programming 45 11-07-2004 06:37 PM
Search and replace text in file using shell script? matthurne Linux - Software 2 11-02-2004 11:11 AM
problem in perl replace command with slash (/) in search/replace string ramesh_ps1 Red Hat 4 09-10-2003 02:04 AM
trying to search and replace text file for single & multiple line breaks separately brokenfeet Programming 7 08-29-2003 02:56 PM
Grep for search, but what for replace? TheSpecial Linux - Software 18 04-28-2003 10:01 AM


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

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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration