Skip to content
Advertisement

Bash issue with floating point numbers in specific format

(Need in bash linux)I have a file with numbers like this

JavaScript

Any way possible I can do these 3 steps?

1st I try this

JavaScript

then

JavaScript

then

JavaScript

Final 1 line solution

JavaScript

Advertisement

Answer

Your “final” solution:

JavaScript

should avoid the useless cat, and also move the backslash in the sed script to the correct place (and I added a ^ anchor and removed the g flag since you don’t expect more than one match on a line anyway);

JavaScript

You might also be able to get rid of at least one useless grep but at this point, I would switch to Awk:

JavaScript

The sub() does what your sed replacement did; the final condition says to print lines which match the regex.

The same can conveniently, but less readably, be written in sed:

JavaScript

assuming your sed dialect supports BRE regex with repetitions like [0-9]{9}.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement