|
sed match closest/nearest pattern
All
i am struggling to raplace some text in a line between two (closest) patterns ,
Code:
line="/home/usr/bin/:/home/usr/devuser,n1.9/bin:/home/usr/root/bin"
i want to replace "devuser,n1.9" with "NEWVAL", basically all teh text from "devuser" until nearest '/' with some new text.
i tried teh following
Code:
echo $line | sed 's/devuser.*\//NEWVAL\//'
i am getting /home/usr/bin/:/home/usr/NEWVAL/bin"
where i am expecting
/home/usr/bin/:/home/usr/NEWVAL/bin:/home/usr/root/bin"
i know sed will match the longest possible pattern, i tried this as well
Code:
echo $line | sed 's/devuser.*[^\/]/NEWVAL/'
but still no luck 
any help will be appreciated.
Thanks in advance.
---------- Post updated at 02:13 AM ---------- Previous update was at 01:30 AM ----------
hey guys,
found something
Code:
echo $line | sed 's/devuser[^\/]*/NEWVAL/'
is giving me the expected output.
any other suggestions are welcome.
Last edited by otheus; 07-02-2009 at 04:59 AM..
Reason: added code tags
|