On 7/21/2016 8:26 AM, bruce wrote:
Hey Tudor, and others..
The test sed I posted works for doing a search/replace of the text
inside the parens...
> foo('txt')
> foo("txt")
however.. if i wanted to craft a sed that uses the entire
>>foo('txt')<< as the search.. then I run into the need to handle the
parens.. and that's the issue..
this doesn't work
sed -i 's/foo('txt')/foo('/dir1/txt') /' *files.dat
sed -i 's/foo\('txt'\)/foo\('/dir1/txt'\)/' *files.dat
If you swap out the apostrophes with quotation marks it should work -
Bash is what I think is getting in your way. On Fedora 23 I have the
following in a text file called test.txt:
The 'test' case for changing foo('txt') to foo("txt") without
changing
bar('txt') to bar("txt") example.
I used the following sed command:
sed -e "s/foo('txt')/foo(\"txt\")/g" test.txt
This is the output:
The 'test' case for changing foo("txt") to foo("txt") without
changing
bar('txt') to bar("txt") example.
Tom