using sed to replace multiple strings
Hi Guys
I know this has been covered in the past but there is a small twist/ a.txt is redcat redhat bluebat b.txt is cat mat hat tat . .thousand keywords i want to use sed to replace cat with mat[example] from b.txt output should be redmat redtat bluebat iv tried the regular sed command but how do i do it for thousand of keywords? thanks |
Quote:
Can you show us what you've go so far. It will make it easier to help you. Ciao, jdk |
Hi
ive got the results using sed. $sed 's/string1/string2/' file1 > file1 the questions is how do i incorprate file names in sed. string1 and string 2 are in b.txt example string1=cat string2=mat |
Use sed to make a sed interpreter script from your b.txt. http://www.grymoire.com/Unix/Sed.html#uh-20
|
thanks.
this link helped. |
Even you can replace the word cat with mat in vi editor, as:
Code:
~$ vi b.txt |
allend's suggestion of creating a sed interpreter script is probably the definitive solution. Another possibility is to loop over all line entries in b.txt:
Code:
while read from to; do --- rod. |
A trick I would probably use would be to run one sed command inside a process substitution, to reformat the file into a sed script that can be used directly in a second instance.
Code:
sed -f <( sed -r 's|(\w+) (\w+)|s/\1/\2/|' b.txt ) a.txt |
All times are GMT -5. The time now is 05:12 PM. |