LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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, 06: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, 06:40 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
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, 06:47 PM   #3
DediPlace
LQ Newbie
 
Registered: May 2005
Posts: 9

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

Regards,
 
  


Reply



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 05:37 PM
Search and replace text in file using shell script? matthurne Linux - Software 2 11-02-2004 10:11 AM
problem in perl replace command with slash (/) in search/replace string ramesh_ps1 Red Hat 4 09-10-2003 01:04 AM
trying to search and replace text file for single & multiple line breaks separately brokenfeet Programming 7 08-29-2003 01:56 PM
Grep for search, but what for replace? TheSpecial Linux - Software 18 04-28-2003 09:01 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 09:07 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
Open Source Consulting | Domain Registration