using sed to replace a pattern in list of files

Hi All,

using the below grep command,I get the following output:

$grep -irl "bc" /home/applmgr/amit > file_list.log
$cat file_list.log
/home/applmgr/amit/xyz.log
/home/applmgr/amit/abc.log

Requirement

Need sed utility to replace "bc" with "xy" pattern in the list of files i.e., file_list.log

I am not getting the output while doing this way:

sed -in '1,$s/bc01/xy01/g' file_list.log

could anyone please help correct this..would appreciate the help..

Thanks for your time!

Regards,

Your sample input and output are not coherent. Your sed expression cointains "bc01" even though none of the sample data contains "bc01". Assuming the "01" is an accident or something, the following will do what you describe, i.e. replace "bc" with "xy".

sed -i 's/bc/xy/g' file_list.log

The -i switch causes sed to perform the replacement in the file, i.e. replacing the file's contents with the new contents. If you have already run the failed command, it will have replaced the file with probably nothing at all, so you will need to run the grep again before you try the new script.

Hi era,

Thanks for the help but it still doesn't work..

Files below consists of "bc01"..

/home/applmgr/amit/xyz.log
/home/applmgr/amit/abc.log

If i use sed this way, it works...

$ sed -i 's/bc/xy/g' xyz.log abc.log

output:

A) cat xyz.log
xy01
6000

B) cat abc.log
xy01
6000
6001

My requirement is :

sed -in '1,$s/bc01/xy01/g' file_list.log --should work for multiple files in file_list.log

where ..

$cat file_list.log
/home/applmgr/amit/xyz.log
/home/applmgr/amit/abc.log

anyone who could suggest the correct way..

Regards,

xargs sed -i 's/bc01/xy01/g' <file_list.log

The -n option causes sed to remove any line which does not match; I'm guessing you don't want that. If you do, you'll need to add a /p option to the s/// command to print the lines which had substitutions made to them; otherwise, the output will be empty files (it will make the substitution but not write the result anywhere).

thanks era now it works..

take care,

regards,