• 0 views
•
link
Inserting delim between numbers and strings in bash
Hi.
How can I insert a delimiter between number and string?
I tried using 'sed' but couldn't get the result I want.
Here's an example and the code I used.
ex) 5c --> 5,c
sed 's/[0-9][a-zA-Z]/[0-9],[a-zA-Z]/g'
Thank you!
• 2,482 views
•
link
3 answers
sed version
sed -r 's/([0-9]+)([a-zA-Z]+)/\1,\2/g'
Perl version
perl -pe 's/([0-9]+)([a-zA-Z]+)/\1,\2/g'
or
perl -pe 's/([0-9]+)([a-zA-Z]+)/$1,$2/g'
• 0 views
•
link
Thank you. It works perfectly!
• 0 views
•
link
In sed .\d and \w might not work,or maybe I don't know how to use.Try this:
sed -e 's/\([0-9]\+\)\([a-zA-Z]\+\)/\1,\2/g' FILE > OUTPUT
• 0 views
•
link
How about this one:
sed -r 's/([0-9])/&,/g' FILE > OUTPUT
it's basically the same as above but without the picket fence in the end.
• 0 views
•
link
Log in to answer this question.