I want to replace a character after every integer number with sed.
Example:
444 d
should go: 444,d
EDIT: The answer of stribizhev helped me out to find a solution with sed (GNU sed) 4.2.2
sed -r 's/([0-9]+)./\\1,/g'
replaces an arbitary character after a number with a comma. The only problem is, that also a number at the end of the line creates an additional comma.
You can use capturing groups to do that:
sed 's/\(\d\+\)./\1,/g'
or (since with GNU sed you can avoid all the escaped parenthesis by using extended regular expressions)
sed -r 's/([0-9]+)./\1,/g'
Here is a demo showing what the regex does .
The [0-9]+
pattern matches an integer number (without decimals) even Iinside longer strings, even within longer words.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.