I have modified the code found here: sed whole word search and replace
I have been trying to use the proper syntax \< and \> for the sed to match multiple terms in a file.
echo "Here Is My Example Testing Code" | sed -e "$(sed 's:\<.>:s/&//ig:' file.txt)"
However, I think, because it's looking into the file, it doesn't match the full word (only exact match) leaving some split words and single characters.
Does anyone know the proper syntax?
Example:
Input:
Here Is My Example Testing Code
File.txt:
example
test
Desired output:
Here Is My Code
解决方案
Modify your sed command as followed should extract what you want,
sed -e "$(sed 's:\<.>:s/&\\w*\\s//ig:' file.txt)"
Brief explanation,
\b matches the position between a word and a non-alphanumeric character. In this case, the pattern 'test' in file.txt would not match 'Testing'.
In this way, modify the searched pattern appended with \w* should work. \w actually matched [a-zA-Z0-9_]
And don't forget to eliminate the space behind each searched pattern, \s should be added.