LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   find with grep and replace it (https://www.linuxquestions.org/questions/linux-newbie-8/find-with-grep-and-replace-it-153040/)

dominant 03-03-2004 11:21 AM

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?

wapcaplet 03-03-2004 11:33 AM

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).

dominant 03-03-2004 11:49 AM

what is [RET] ?

dominant 03-03-2004 11:53 AM

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.


wapcaplet 03-03-2004 01:11 PM

[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.


All times are GMT -5. The time now is 06:05 AM.