3

I have following type of data in my .log file:

Cell[BoxData["0.8693473380926441`"]
Cell[BoxData["100.40266203596555`"]
Cell[BoxData["23.338724857049048`"]
Cell[BoxData["0.25720321805387686`"]
Cell[BoxData["66.85236878385265`"]

I want to grep only the numeric numbers, like:

0.8693473380926441
100.40266203596555
23.338724857049048
0.25720321805387686
66.85236878385265

I have tried, grep -Po '\[.*?]', but it only eliminates one brackets. Any help will be appreciated.

4 Answers 4

4

awk is better for this:

awk -F '["`]' '{print $2}' file

That sets the field separator as either " or a tilde and then prints the second column/field.

Output:

0.8693473380926441
100.40266203596555
23.338724857049048
0.25720321805387686
66.85236878385265
2
  • Its perfect, Thank you very much Jun 24, 2019 at 15:53
  • @AmanullahMalik. You are welcome. Jun 24, 2019 at 15:56
0

I tried with below mentioned command and worked fine

 sed 's/.*\["//g' filename| sed 's/`"\]//g'

output

0.8693473380926441
100.40266203596555
23.338724857049048
0.25720321805387686
66.85236878385265
1
  • If you're going to use sed for this then you don't need to call it twice. You can use -e for multiple statements. Jul 2, 2019 at 16:16
0

Any chance anyone can answer the question in the subject instead of the example. I am trying to use awk to grab the number in “[nnn]” and while awk -F'\[' '{print $2}' | awk -F'\]' '{print $1}’ works, it sure seem ugly. I have tried -F’[[]]’ and -F’[\[\]]’ but neither work

0

grep for what it is you actually want. What you want from that is just the numbers. You want some digits, and a period, and some digits, so:

egrep  '[0-9]+\.[0-9]+' -o foo.txt

The -o says "Only print the part that matches, not the entire line".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.