Thanks for the quick reply. I am facing a small issue. Its replacing other numbers too. I want to specifically replace only percentages from 90 to 100.
Aia,
Standard sed uses BREs; not EREs. Basic regular expressions do not include alternation (i.e., BRE|BRE ). Furthermore, we don't know what separates a percentage to be quoted from its surroundings. With the following input:
123% 992% 100% 90% 93%92%,100%(90%+10%) 77.99%
a standard sed (with your suggested command) produces the output:
123% 992% 100% 90% 93%92%,100%(90%+10%) 77.99%
(which I do not believe is what is wanted) and your perl script produces:
but, without confirmation that that really is what is wanted from ctrid, I'm not going to try to produce a different sed or awk script that does what I might think would be a more reasonable interpretation.
ctrid,
Please give us a clear specification of what, if any, characters or strings appearing adjacent to a percentage should keep it from being quoted. (If a period or comma is to be interpreted as part of a percentage, are these characters locale specific?) Should something like 91.50% (in the C Locale) be quoted (since it is in the range 90% to 100%, inclusive)?
Very good catch. Even I didn't anticipate the decimals.
As you said there could be decimals.
But
992%
or
93%92%
or
100%(90%+10%)
would not be in my input text file. All percentages are delimited by space and no periods or any other characters appear anywhere.
Hence only danger I see is of decimals. Don, Thanks once again for pointing out this.
Aia, your one liner is cool, it works for now. As Don said I have an issue only if my input file changes with decimals. How do I modify this perl statement to take care of that?
The request was to quote percentages between 90% and 100% inclusive when the percentage appears at the start of a line or is preceded by a space character. So, with input like:
Get a loan of 1000 dollars at 5% interest.
no change should be made. But your suggestion changes it to: