Using bash, how do I find all files containing a specific string and replace them with an existing file?

Find . -type f | grep 000000 | tr \\n \\0 | xargs -0i+ cp ~/offblack.png.

This worked perfectly, now reading through the man pages to understand exactly whats going on. I was not familiar with the tr command until now. – Holly Anders Aug 4 at 20:44.

Here's what I would use: find (your find args here) \ | xargs fgrep '000000' /dev/null \ | awk -F: '{print $1}' \ | xargs -n 1 -I ORIGINAL_FILENAME /bin/echo /bin/cp /path/to/offblack. Png ORIGINAL_FILENAME Expanding, find all the files you're interested in, grep inside of them for the string '000000' (adding /dev/null to the list of files in case one of the generated fgreps ended up with only one filename - it ensures the output is always formatted as "filename: "), strip out only the filenames, then one-by-one, copy in offblack. Png over those files.

Note that I inserted a /bin/echo in there. That's your dry-run. Remove the echo to get it to run for real.

If what you mean is that the filenames contain "000000": find . -type f -a -name '*000000*' -exec /bin/echo /bin/cp /path/to/offblack. Png {} \; Much simpler.

:-) Find every file under the current directory with a name containing your string and exec the copy of offblack. Png over it. Again, what I've given you there is a dry-run.

Remove the echo for your live fire drill. :-).

– MichaÅ‚ Å rajer Aug 5 at 9:12 As I called out in the descriptions of each of the commands in my response, those are "dry-run" versions of them; the expectation (again, mentioned alongside each command's description in my answer) is that OP would run it as-is first to see what would have happened, and then remove the echo when comfortable it was going to to what was wanted. I pretty much always follow that paradigm with potentially destructive commands like this. :-) – Brian Gerard Aug 5 at 18:04 Right - it's a very good practice.

– MichaÅ‚ Å rajer Aug 6 at 10:41.

Let's try and use Bash a bit more: for read -r filename do hit="" for read -r do if $REPLY == *000000* then hit=$filename break fi done.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions