How do I use sed to remove decimal numbers from a string?
this would be easier with awk
, at least for me
echo "Abandoned 16 1.10 2.62 3.50" | awk '{print $1FS$2}'
but is the list of numbers random afterwards?
if so, this works too
echo "Abandoned 16 1.10 2.62 3.50" | sed -r 's/\s([0-9]+)\.([0-9]+)//g'
note that \s
catches the white space, and that the numbers before and after the decimal are saved, so if you want to retain them and do something with them you can access them with \1
and \2
respectfully
Why catch the white sapce? well imagine if 16 came after 3.50 in your example you would then return
Abandoned [5spaces*] 16
*I can only insert one space in this <textarea>