SED - substitution
Hi all,
I'm having a problem by substituting part of this sentence that is save in 'file': inp1.inTicks_vl(ch_inTicks_vl); I use the following SED command: sed -i 's/[^ ]*\([0-9]*\).inTicks_vl([^ ]*);/inTicks_vl\1/' file so that the sentence looks like this at the end: inTicks_vl1 I want to move the number, that is part of the first name in the sentence, to the end of the second name in the sentence and erase all the rest. But what I get with my command is: inTicks_vl so, I believe the command is not recognising that the first name is composed by letters and than by a number... [^ ]* is reading everything and [0-9]* doesn't find anything left... Would somebody know how to solve this problem? The first name, which has a number at the end, can have random characters... |
In sed, awk and grep, use .* to match zero or more of any characters. The asterisk matches zero or more of the preceding character. Not zero or more characters. If you want to match a literal period in the LHS, then use "\.".
---- On the first reading, I didn't pick up on a space. It's better to put sed code in code blocks. Code:
echo 'inp1.inTicks_vl(ch_inTicks_vl);' | sed 's/^[^ ]*\([[:digit:]]\)\.inTicks_vl[^ ]*/inTicks_v1\1/' |
Hi jschiwal,
thanks a lot for the explanation. It helped a lot. I just wanted to ask one more thing: is [[:digit:]] the same thing as [0-9]? Which is the difference? |
They are the same.
There is a complete list of the definitions here: http://tldp.org/LDP/abs/html/x16608.html |
Thanks for the link pixellany :)
|
There is also a "regex (7)" manpage as well.
|
All times are GMT -5. The time now is 02:01 PM. |