Hi,
I am trying to find some float number (like -1234.5678) in a huge text file using grep, so I thought about:
grep -n '-1234.5678'
but I get errors, do you know what is the right way using grep and why? there is anything easier?
Thanks
Hi,
I am trying to find some float number (like -1234.5678) in a huge text file using grep, so I thought about:
grep -n '-1234.5678'
but I get errors, do you know what is the right way using grep and why? there is anything easier?
Thanks
If you enter this in command line, try
grep -n "\-1234.5678"
to avoid interpreting 1234.5678 as a flag.
Use grep -e
in cases where the pattern might start with a hyphen.
grep -n -e -1234.5678
you can try these
$ cat file
1 2 3 -1234.5678 4 5 1.4
ass 34.55334 aslfjas
$ awk '{for(i=1;i<=NF;i++)if($i~/^-?[0-9]+\.[0-9]+$/){print $i}}' file
-1234.5678
1.4
34.55334
$ grep -oE "\-?[0-9]+\.[0-9]+" file
-1234.5678
1.4
34.55334