Find and Replace

After running a command like

grep -ir files2/ *

This will find all the files that contain "files2/" in it.

For example if it finds

files2/dir/today
files2/dir/yesterday
files2/dir/2daysago

Now it may find 100 instances, so is there a quick find and replace command I can use? I basically want to remove "files2" from all instances. tia.

What do you want. remove file2 from filenames or from the output of the grep command ? If you want to remove file2 from the output of grep command then use 'sed'

PS - i have limited access to internet so may not be able to answer very promptly.

If you want to remove "files2/" from the file itself, vi the file and type below and enter

:%s/^files2\///g

If you want to repalce from grep output

# grep files2 filename | sed 's/files2\///'

This all will give u output
dir/today
dir/yesterday
dir/2daysago

Ok, maybe I should describe what I want to do more clearly.

On a windows server where we ftp files to, we have unix scripts that move files to certain directories on the windows server that begin with "data2/". That has changed, they are removing "data2/" from the path, not to mention different servers but thats not my question.

I have about 30 production unix scripts to modify in a certain unix directory that contain "data2/" instances. I cant rename the scripts, I basically have to remove the "data2"/ from each one. Is there a command I can run from the prompt, or do I have to do each one with VI. Either way you guys advise to be easier, how do you do it? :o

grep -ir files2/ * > list.txt
while read file
do
  sed -i -e "s/files2\///g" $file
done < list.txt

You need to have GNU sed for the -i flag. If you dont have that, replace sed with perl.