Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 09-28-2005, 02:51 PM   #1
Registered: Jun 2004
Distribution: Ubuntu 6.10 Edgy Eft
Posts: 61

Rep: Reputation: 15
Best search & replace program

I have 1,000 text files spread over 200 folders at various depths. I want to replace "This long, complex string" with "this different, long and complex string" in every file.

So, I want to say to my command line program:

"Go look in this folder and replace every instance of X with Y."

What script/program on the command line can do this?

I'm familiar with search and replace in vi and search with grep. I imagine grep can pipe to vi for this maybe?
Old 09-28-2005, 03:05 PM   #2
Senior Member
Registered: May 2005
Distribution: Ubuntu with IceWM
Posts: 1,776

Rep: Reputation: 86
Doing this Google search, I found this script. Does that help?
Old 09-28-2005, 03:39 PM   #3
Registered: Mar 2003
Distribution: Fedora
Posts: 42

Rep: Reputation: 15
Using sed within a shell script could work, too. You have to look out for whitespace and newlines, though.

Old 09-28-2005, 03:41 PM   #4
LQ Newbie
Registered: Mar 2005
Posts: 29

Rep: Reputation: 15
I don't know about the piping grep to vi option, you would probably want vi to run some sort of batch process or something that I don't really know anything about.

it really wouldnt take much to write a perl script to do this. I know that if i was faced with this problem that is the approach I would take.

this article has most of what you need:


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
Does anyone know of a bash script can search & replace txt in a file. jimwelc Linux - Newbie 6 09-15-2008 12:13 AM
How to "Search & Replace" in html files using Perl? rebel Red Hat 8 04-09-2005 12:58 PM
Python search and replace Accordion Programming 1 02-22-2005 07:54 PM
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 > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 12:53 AM.

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