Currently I have the following to separate the numeric values. However the decimal point get separated.
ls -lrt *smp*.cmd | awk '{print $NF}' | sed 's/^.*\///' | sed 's/\([0-9][0-9]*\)/ & /g'
As an example on the files
n02-z30-dsr65-terr0.50-dc0.05-4x3smp.cmd
n02-z30-dsr65-terr0.50-dc0.01-8x6smp.cmd
n02-z30-dsr65-terr0.50-dc0.006-8x6smp.cmd
n02-z30-dsr65-terr0.50-dc0.008-8x6smp.cmd
I am getting
n 02 -z 30 -dsr 65 -terr 0 . 50 -dc 0 . 05 - 4 x 3 smp.cmd
n 02 -z 30 -dsr 65 -terr 0 . 50 -dc 0 . 01 - 8 x 6 smp.cmd
n 02 -z 30 -dsr 65 -terr 0 . 50 -dc 0 . 006 - 8 x 6 smp.cmd
n 02 -z 30 -dsr 65 -terr 0 . 50 -dc 0 . 008 - 8 x 6 smp.cmd
I would like to have something like the following instead
n 02 -z 30 -dsr 65 -terr 0.50 -dc 0.05 - 4 x 3 smp.cmd
n 02 -z 30 -dsr 65 -terr 0.50 -dc 0.01 - 8 x 6 smp.cmd
n 02 -z 30 -dsr 65 -terr 0.50 -dc 0.006 - 8 x 6 smp.cmd
n 02 -z 30 -dsr 65 -terr 0.50 -dc 0.008 - 8 x 6 smp.cmd
In this way the numbers are separated without detaching the decimal point.
Try:
ls -lrt *smp*.cmd | awk '{print $NF}' | sed 's/^.*\///' | sed 's/\([0-9][0-9.]*\)/ & /g'
ctsgnb
3
@kristinu
sed 's/ \. /./' yourfile
Do you still have sorting issue with that list ?
$ echo 'n02-z30-dsr65-terr0.50-dc0.05-4x3smp.cmd' | sed 's/\([0-9][0-9]*[.]*[0-9]*\)/ & /g'
n 02 -z 30 -dsr 65 -terr 0.50 -dc 0.05 - 4 x 3 smp.cmd
birei
5
Hi kristinu,
You may need the GNU version of 'sed' to use next command:
$ ... | sed 's/\([0-9]\+\(\.[0-9]\+\)\?\)/ \1 /g'
n 02 -z 30 -dsr 65 -terr 0.50 -dc 0.05 - 4 x 3 smp.cmd
n 02 -z 30 -dsr 65 -terr 0.50 -dc 0.01 - 8 x 6 smp.cmd
n 02 -z 30 -dsr 65 -terr 0.50 -dc 0.006 - 8 x 6 smp.cmd
n 02 -z 30 -dsr 65 -terr 0.50 -dc 0.008 - 8 x 6 smp.cmd
Regards,
Birei
Not much now, just that having the complete number will make my life much easier, especially if I got to do a sort after.
ctsgnb
7
add the dot in the list then :
... | sed 's/\([0-9][0-9.]*\)/ & /g'
Getting confused on the difference between the following two things
sed 's/\([0-9][0-9.]*\)/ & /g'
sed 's/\([0-9][0-9]*[.]*[0-9]*\)/ & /g'
They both seem to work in my case. I tried on the files below
n02-z30-dsr65-terr11-dc0.05-4x3smp.cmd
n02-z30-dsr65-terr12.1-dc0.05-4x3smp.cmd
n02-z30-dsr65-terr123.12-dc0.05-4x3smp.cmd
ctsgnb
9
When 2 solutions works, use the most simple one.
---------- Post updated at 02:25 PM ---------- Previous update was at 02:23 PM ----------
In case you get a version number like :
1.0.2.4
the first solution will still match it into 1 single matching , the second solution won't.
$ echo "1.0.2.4" | sed 's/\([0-9][0-9.]*\)/ & /g'
1.0.2.4
$ echo "1.0.2.4" | sed 's/\([0-9][0-9]*[.]*[0-9]*\)/ & /g'
1.0 . 2.4
Just for a better display understanding :
$ echo "1.0.2.4" | sed 's/\([0-9][0-9.]*\)/_&_/g'
_1.0.2.4_
$ echo "1.0.2.4" | sed 's/\([0-9][0-9]*[.]*[0-9]*\)/_&_/g'
_1.0_._2.4_
So far in your file you don't have numeric string with multiple dot in it :
that is the reason why didn't you notice the difference.