Reputation: 2399
I'm new to the Unix sed command and I would like to know how to double the first digit in a string?
Suppose we have a string "F0o", How do I double the first digit in the string?
I tried echo f0o | sed s/0/00/
, giving f00o
,
but this will only work for 0s. If the string is "f12o" the output should be f112o
, simply doubling the first digit in the string.
Is there a command where I can specifically target digits only?
Upvotes: 1
Views: 853
Reputation: 123448
I would like to know how to double the first digit in a string
You could say:
sed 's/[0-9]/&&/' filename
This would print the first digit in a line two times.
$ sed 's/[0-9]/&&/' <<< "f12o"
f112o
Upvotes: 2