Hey guys..
Sed question.. should be simple, but after stack/net searches, lots or trials.. can't seem to get it..
I've got a case
foo('txt') foo("txt")
I'd like to have
foo('/dir1/txt') foo("/dir1/txt")
Now. I do a simple sed search/replace if it just focuses on the txt, but crafting a sed that uses the entire input as a search due to the parens '()' is a bit painful! Doing the sed using the ( for the ( wasn't quite successful!
for just the txt..
sed -i 's/'txt'/'dir1/txt'/' *files.dat sed -i 's/"txt"/"dir1/txt"/' *files.dat
these work...
any thoughts on how to handle the parens would be cool!
just irks me that I couldn't see what I missed.
thanks!
On Thu, Jul 21, 2016 at 3:00 PM, bruce badouglas@gmail.com wrote:
Hey guys..
Sed question.. should be simple, but after stack/net searches, lots or trials.. can't seem to get it..
I've got a case
foo('txt') foo("txt")
I'd like to have
foo('/dir1/txt') foo("/dir1/txt")
Now. I do a simple sed search/replace if it just focuses on the txt, but crafting a sed that uses the entire input as a search due to the parens '()' is a bit painful! Doing the sed using the ( for the ( wasn't quite successful!
for just the txt..
sed -i 's/'txt'/'dir1/txt'/' *files.dat sed -i 's/"txt"/"dir1/txt"/' *files.dat
these work...
any thoughts on how to handle the parens would be cool!
just irks me that I couldn't see what I missed.
thanks!
Try like this:
cat /tmp/1.txt foo('/dir1/txt')
sed -e 's#'txt'#'dir1/txt'#' /tmp/1.txt foo('/dir1/dir1/txt')
Or: sed -e 's/'txt'/'dir1\/txt'/' /tmp/1.txt
You need to escape the / in the replacement string.
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
thanks
On Thu, Jul 21, 2016 at 8:14 AM, Todor Petkov petkovptodor@gmail.com wrote:
On Thu, Jul 21, 2016 at 3:00 PM, bruce badouglas@gmail.com wrote:
Hey guys..
Sed question.. should be simple, but after stack/net searches, lots or trials.. can't seem to get it..
I've got a case
foo('txt') foo("txt")
I'd like to have
foo('/dir1/txt') foo("/dir1/txt")
Now. I do a simple sed search/replace if it just focuses on the txt, but crafting a sed that uses the entire input as a search due to the parens
'()'
is a bit painful! Doing the sed using the ( for the ( wasn't quite successful!
for just the txt..
sed -i 's/'txt'/'dir1/txt'/' *files.dat sed -i 's/"txt"/"dir1/txt"/' *files.dat
these work...
any thoughts on how to handle the parens would be cool!
just irks me that I couldn't see what I missed.
thanks!
Try like this:
cat /tmp/1.txt foo('/dir1/txt')
sed -e 's#'txt'#'dir1/txt'#' /tmp/1.txt foo('/dir1/dir1/txt')
Or: sed -e 's/'txt'/'dir1\/txt'/' /tmp/1.txt
You need to escape the / in the replacement string.
users mailing list users@lists.fedoraproject.org To unsubscribe or change subscription options: https://lists.fedoraproject.org/admin/lists/users@lists.fedoraproject.org Fedora Code of Conduct: http://fedoraproject.org/code-of-conduct Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines Have a question? Ask away: http://ask.fedoraproject.org
On Thu, Jul 21, 2016 at 3:26 PM, bruce badouglas@gmail.com 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
cat /tmp/1.txt ; echo; sed -e "s#foo('txt')#foo('/dir1/txt')#;s#foo("txt")#foo('/dir1/txt')#" /tmp/1.txt foo('txt') foo("txt")
foo('/dir1/txt') foo('/dir1/txt')
This?
hey todor..
I'll give it a try.. I was thinking it's the parens.. overlooked the fact that i introduced '/' in the replace.. which might have caused issue.. but the '/' was successful in the test with just the text inside the ()..
On Thu, Jul 21, 2016 at 8:59 AM, Todor Petkov petkovptodor@gmail.com wrote:
On Thu, Jul 21, 2016 at 3:26 PM, bruce badouglas@gmail.com 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
cat /tmp/1.txt ; echo; sed -e "s#foo('txt')#foo('/dir1/txt')#;s#foo("txt")#foo('/dir1/txt')#" /tmp/1.txt foo('txt') foo("txt")
foo('/dir1/txt') foo('/dir1/txt')
This?
users mailing list users@lists.fedoraproject.org To unsubscribe or change subscription options: https://lists.fedoraproject.org/admin/lists/users@lists.fedoraproject.org Fedora Code of Conduct: http://fedoraproject.org/code-of-conduct Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines Have a question? Ask away: http://ask.fedoraproject.org
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
On Thu, Jul 21, 2016 at 1:00 PM, bruce badouglas@gmail.com wrote:
Now. I do a simple sed search/replace if it just focuses on the txt, but crafting a sed that uses the entire input as a search due to the parens '()' is a bit painful! Doing the sed using the ( for the ( wasn't quite successful!
localhost:~% sed 's,^foo((.)txt(.))$,foo(\1/dir1/txt\2),' << EOF foo('txt') foo("txt") EOF foo('/dir1/txt') foo("/dir1/txt")
Tet
thanks.. guys..
just a brain screwup.. should be ok now.. thanks for the eyeballs..
owe you guys oj!
On Thu, Jul 21, 2016 at 11:01 AM, Tethys tethys@gmail.com wrote:
On Thu, Jul 21, 2016 at 1:00 PM, bruce badouglas@gmail.com wrote:
Now. I do a simple sed search/replace if it just focuses on the txt, but crafting a sed that uses the entire input as a search due to the parens
'()'
is a bit painful! Doing the sed using the ( for the ( wasn't quite successful!
localhost:~% sed 's,^foo((.)txt(.))$,foo(\1/dir1/txt\2),' << EOF foo('txt') foo("txt") EOF foo('/dir1/txt') foo("/dir1/txt")
Tet
-- I saw cout being shifted "Hello world" times to the left and stopped right there. — Steve Gonedes -- users mailing list users@lists.fedoraproject.org To unsubscribe or change subscription options: https://lists.fedoraproject.org/admin/lists/users@lists.fedoraproject.org Fedora Code of Conduct: http://fedoraproject.org/code-of-conduct Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines Have a question? Ask away: http://ask.fedoraproject.org
On Thu, Jul 21, 2016 at 08:00:44AM -0400, bruce wrote:
Hey guys..
Sed question.. should be simple, but after stack/net searches, lots or trials.. can't seem to get it..
I've got a case
foo('txt') foo("txt")
I'd like to have
foo('/dir1/txt') foo("/dir1/txt")
Now. I do a simple sed search/replace if it just focuses on the txt, but crafting a sed that uses the entire input as a search due to the parens '()' is a bit painful! Doing the sed using the ( for the ( wasn't quite successful!
for just the txt..
sed -i 's/'txt'/'dir1/txt'/' *files.dat sed -i 's/"txt"/"dir1/txt"/' *files.dat
these work...
any thoughts on how to handle the parens would be cool!
just irks me that I couldn't see what I missed.
Two more possibilities (the short output lines were unchanged):
# search for entire string, replace only txt $ sed '/foo(.txt.)/s,txt,/dir/txt,' tst.txt foo('/dir/txt') bar('txt') foo('bar') foo("/dir/txt") bar("txt") foo("bar")
# capture unchanging parts as \1 and \2 using grouping ( & ) $ sed 's,(foo(.)txt(.)),\1/dir/txt\2,' tst.txt foo('/dir/txt') bar('txt') foo('bar') foo("/dir/txt") bar("txt") foo("bar")