regex in shell scripts
Hi all..
Code:
[vinay@TEG test]$ echo 'text[2*?!]' | sed 's/text*[2-4]*/vinay/' Code:
[vinay@TEG test]$ echo 'text[2*?!]' | sed 's/text*[2-4]/vinay/' |
wrong, although I guess you knew that already.
Quote:
tex2 tex3 tex4 text2 text3 text4 textt2 textt3 textt4 Basically, match tex then any number of the character t (including zero) followed by a number between 2 and 4 |
Try:
Code:
echo 'text[2*?!]'|sed 's/\(text\)\(\[[2-4]\)/vinay\2/' \(\[[2-4]\) searches for a litteral [ character followed by a number between 2 and 4 Therefore \1 refers to text (but we are not using this part. \2 refers (in this instance) to [2 We replace the search with vinay followed by the second reference [2 the rest of the string is kept as it wasn't part of the search. HTH, Dis |
Hi Disillusionist
Quote:
vinay[2*?!] Actually output should be vinay[2 Also you are escaping [ with \ to match [, I hope its not necessary..why its matching whole [2*?!] ?? Till now i have read lot of material on regex..still struggling to find answers.. |
Quote:
Quote:
[2-4) and putting it back in the replacement string with \2 ... '*?!]' wasn't matched and won't be replaced. Cheers, Tink |
All times are GMT -5. The time now is 03:52 AM. |