Some other variants:
Every example bellow uses this regex:
(\d+\.\d*|\.\d+|\d+)
It matches, (in one group) the ddd. ddd.ddd .ddd ddd. If your decimals are different, for example don't want capture the .ddd (only decimal) variant, just remove it from the regex.
Usage for one file/string
#using `paste`
echo "bench-100-net-buffering1000.out:Throughput: 3212.97" | grep -Eo '(\d+\.\d*|\.\d+|\d+)' | paste -s -
# using echo for making the "one line"
echo $(grep -Eo '(\d+\.\d*|\.\d+|\d+)' <<< "bench-100-net-buffering1000.out:Throughput: 3212.97")
#HERESTRING and different separator
grep -Eo '(\d+\.\d*|\.\d+|\d+)' <<< "bench-100-net-buffering1000.out:Throughput: 3212.97" | paste -sd, -
#process substitution.. ;)
paste -sd ' ' <(grep -Eo '(\d+\.\d*|\.\d+|\d+)' <<< "bench-100-net-buffering1000.out:Throughput: 3212.97")
Same as above for multiple files, using bash loops. In the examples using ff* for the filenames.
#Using null-term find
while IFS= read -r -d '' file; do
grep -Eo '(\d+\.\d*|\.\d+|\d+)' "$file" | paste -s -
done < <(find . -maxdepth 1 -type f -name ff\* -print0)
# or alternative - also prints filenames
while IFS= read -r -d '' file; do
echo "$file:" $(grep -Eo '(\d+\.\d*|\.\d+|\d+)' $file)
done < <(find . -maxdepth 1 -type f -name ff\* -print0)
echo Using FOR loop
for file in ff* ; do
grep -Eo '(\d+\.\d*|\.\d+|\d+)' "$file" | paste -s -
done
perl variants:
perl -0777 -nE 'say "@{[/(\d+\.\d*|\.\d+|\d+)/g]}"' ff*
also prints filenames
perl -0777 -nE 'say "$ARGV @{[/(\d+\.\d*|\.\d+|\d+)/g]}"' ff*
also by using different field separator \t
perl -0777 -nE '$"="\t";say "$ARGV @{[/(\d+\.\d*|\.\d+|\d+)/g]}"' ff*
All perl solution uses the baby-cart operator. It is usually not recommented for a production code, but acceptable for the oneliners.
demo:
perl -0777 -nE 'say "@{[/(\d+\.\d*|\.\d+|\d+)/g]}"' <<< "some-111-decimal-222.-another-333.33-only-frac-.444.txt"
output
111 222. 333.33 .444