ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
I have some text that I would like to replace, I want only to replace the values associated with the text, or I can replace the entire line. However I am finding that some of the reg expressions I am using do not seem to work.
Here is the line in the file:
@ xaxis label char size 3.03
I want to replace the numbers. How best to match? I can match and get the text string i.e. "@ xaxis label char size", but I want to replace the entire line. How best?
With certain types of regexes (in sed, in this case, but awk too), expressions like \(blah\) can be referenced on the right hand side. Each time a \(blah\) is encountered, it can be re-printed in the output by referencing it with a \1 or \2 or \3 etc.. Each match of \(blah\) will be incrementally referenced. There may be a limit of 9 such matches I believe - you'd need to check the docs on that though.
The [[:digit:]+] is a regex match for a quantity of one or more digits.
Does this clear it up?
Last edited by GrapefruiTgirl; 08-11-2010 at 11:24 AM.
Reason: added stuff in ( ... )
Plus - you could (and maybe should) tweak the end of the entire match, to properly account for the period and anything which might follow the decimal number(s), unless you're sure that the numbers part is the last thing on the line; otherwise, the end of the line following the number(s) will be lost.
Here's a slight improvement - now, if the digit(s) you are replacing happen to be more than a single digit (followed by anything), it will still work - but it still depends on the numbers bit being the last thing on the line.