LinuxQuestions.org
Review your favorite Linux distribution.
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-03-2004, 11:21 AM   #1
dominant
Member
 
Registered: Jan 2004
Posts: 409

Rep: Reputation: 30
find with grep and replace it


I want to find a string in a directory (Recursively) and replace it with another string.

Is there any relevant command to do the job?
 
Old 03-03-2004, 11:33 AM   #2
wapcaplet
LQ Guru
 
Registered: Feb 2003
Location: Colorado Springs, CO
Distribution: Gentoo
Posts: 2,018

Rep: Reputation: 48
grep is really only for finding matches; it doesn't do anything by way of replacing. sed (stream editor) is probably closer to what you're looking for. perl can also do it fairly easily, if you have that installed. Check out Searching and Replacing (Linux Cookbook).
 
Old 03-03-2004, 11:49 AM   #3
dominant
Member
 
Registered: Jan 2004
Posts: 409

Original Poster
Rep: Reputation: 30
what is [RET] ?
 
Old 03-03-2004, 11:53 AM   #4
dominant
Member
 
Registered: Jan 2004
Posts: 409

Original Poster
Rep: Reputation: 30
there are the error that i received

Code:

# perl -pi -e "s/htmlentities//g;" *
Can't do inplace edit: bilder is not a regular file, <> line 16878.
Can't do inplace edit: bin is not a regular file, <> line 16878.
Can't do inplace edit: config is not a regular file, <> line 17596.
Can't do inplace edit: convert is not a regular file, <> line 17596.
Can't do inplace edit: coursefiles is not a regular file, <> line 19358.
Can't do inplace edit: data is not a regular file, <> line 20176.
Can't do inplace edit: docs is not a regular file, <> line 21547.
Can't do inplace edit: help is not a regular file, <> line 42565.
Can't do inplace edit: html is not a regular file, <> line 42717.
Can't do inplace edit: imagemaps is not a regular file, <> line 42717.
Can't do inplace edit: images is not a regular file, <> line 42717.
Can't do inplace edit: include is not a regular file, <> line 42717.
Can't do inplace edit: lang is not a regular file, <> line 45212.
Can't do inplace edit: lib is not a regular file, <> line 47790.
Can't do inplace edit: libexec is not a regular file, <> line 47790.
Can't do inplace edit: log is not a regular file, <> line 47923.
Can't do inplace edit: logos is not a regular file, <> line 48022.
Can't do inplace edit: low_cat is not a regular file, <> line 48068.
Can't do inplace edit: man is not a regular file, <> line 49750.
Can't do inplace edit: modules is not a regular file, <> line 50716.
Can't do inplace edit: mysqldata is not a regular file, <> line 50716.
Can't do inplace edit: objects is not a regular file, <> line 52353.
Can't do inplace edit: plugins is not a regular file, <> line 53010.
Can't do inplace edit: sonderzeichen is not a regular file, <> line 53015.
Can't do inplace edit: sql is not a regular file, <> line 53015.
Can't do inplace edit: src is not a regular file, <> line 53015.
Can't do inplace edit: syntax_highlight is not a regular file, <> line 54906.
Can't do inplace edit: templates is not a regular file, <> line 54906.
Can't do inplace edit: tmp is not a regular file, <> line 54922.
Can't do inplace edit: www is not a regular file, <> line 57175.
 
Old 03-03-2004, 01:11 PM   #5
wapcaplet
LQ Guru
 
Registered: Feb 2003
Location: Colorado Springs, CO
Distribution: Gentoo
Posts: 2,018

Rep: Reputation: 48
[RET] I presume is the enter key.

It looks like it's giving errors on all the directory names; I don't think that command will do replacing on directories, just on the files that are in the current directory. You could do all the subdirectories manually, but that would be a pain if there are a lot of them. An easier way would be to use a find command on all the files you want to replace (for example, all *.html files), and then run sed on each one. Something like this:

find . -name '*.html' -exec sed -e "s/htmlentities//g;"

The first part (find . -name '*.html') finds all files in the current directory and all subdirectories with an html extension. The second part (-exec and so on) tells find to run the given sed command on each file it finds. I'm not sure about the syntax, so you may want to search around for sed howtos.
 
  


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
find and replace happy78 Programming 11 09-10-2005 10:21 AM
How to search and replace a text using grep DediPlace Linux - General 2 05-29-2005 06:47 PM
Find and Replace? duerra Linux - General 9 01-28-2004 04:07 AM
Grep for search, but what for replace? TheSpecial Linux - Software 18 04-28-2003 09:01 AM
trying to use find and grep, but don't know well enough. duhduhdude Linux - Newbie 9 03-22-2003 08:44 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:05 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