Suppose I have a file (workingFile.txt) that contains the following:
and I have another file (inputFile.txt) that contains:
I would like to replace any line in workingFile.txt that contains any term from inputFile.txt in its entirety with the term from inputFile.txt prefixed with the "
My actual use case is more complex than this but hopefully this simplified example conveys my issue. My current script looks something like:
When I run it, I keep getting the following error:
What's the proper syntax? I've read that BSD
Thanks in advance!
Code:
>spONEsometextgoes here
foo
bar
>spTWOsome more text is here
alpha
bravo
and I have another file (inputFile.txt) that contains:
Code:
ONE
TWO
I would like to replace any line in workingFile.txt that contains any term from inputFile.txt in its entirety with the term from inputFile.txt prefixed with the "
>
" to result in:
Code:
>ONE
foo
bar
>TWO
alpha
bravo
My actual use case is more complex than this but hopefully this simplified example conveys my issue. My current script looks something like:
Bash:
#!/usr/local/bin/bash
inputfile="inputFile.txt"
workingfile="workingFile.txt"
while IFS= read -r line
do
sed "/$line/c\>$line" $workingfile
done < "$inputfile"
When I run it, I keep getting the following error:
Code:
sed: 1: "/ONE/c\>ONE": extra characters after \ at the end of c command
sed: 1: "/TWO/c\>TWO": extra characters after \ at the end of c command
What's the proper syntax? I've read that BSD
sed
may require a newline after c\
but I couldn't get that to work either.Thanks in advance!