hypnotx
asked on
Shell scripting to use input from one file to do a find and replace in another.
I would like to create a shell script that takes a list from FILE_A and uses it as the input for a sed command that does an edit in FILE_B.
is there some way to grep each and every line of FILE_A and pass each line to sed to edit FO:E_B (or create a FILE_C' which would be safer)?
for example FILE_A conains a list of files:
...
/dir1/file1
/dir1/file2
..
FILE_B contains a bunch of information but will also have the references to files listed in FILE_A
...
blah blah this
blah blah that
/dir1/file1
blah blah blah
/dir1/file2
...
what I am basically looking for is a way to do:
sed 'a/<junk from FILE_A/<replace with edited junk from FILE_A>/g' FILE_B
TIA
is there some way to grep each and every line of FILE_A and pass each line to sed to edit FO:E_B (or create a FILE_C' which would be safer)?
for example FILE_A conains a list of files:
...
/dir1/file1
/dir1/file2
..
FILE_B contains a bunch of information but will also have the references to files listed in FILE_A
...
blah blah this
blah blah that
/dir1/file1
blah blah blah
/dir1/file2
...
what I am basically looking for is a way to do:
sed 'a/<junk from FILE_A/<replace with edited junk from FILE_A>/g' FILE_B
TIA
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
New point value and a split
ASKER
Now I am having a problem with the following script:
for i in `cat mylist.txt`
do
sed 's/$i/# $i/g' file2.txt > newfile.txt
done
This is what I am trying to do but I am having problems passing the $i variable to the sed command. I know that the for part is working because if I change the sed line to an 'echo $i' I can see what I want to pass to the sed command. Any help? (Yes, I am trying to comment lines out of a config file using the input from a list that I have created in a different file.)