1

I have a file like:

number_of_x     100 # total number of x
number_of_y     2000 # total number of y
total_rate     1.67 # rate
blah1     0.876 # blah1
blah2     10450 # blah2

I would like to extract numbers related to, say, number_of_y and total_rate, for example, output here is:

2000
1.67

This is the closest I can get:

grep -E 'number_of_y|total_rate' my_file | grep -Eo '[0-9.]*'
1

Maybe awk will be helpful:

grep -E 'number_of_y|total_rate' my_file | awk '{print $2}'

Change $2 on whatever column you would like to show

| improve this answer | |
  • 4
    Why not just awk '/number_of_y|total_rate/ {print $2}' my_file? – steeldriver Feb 23 '16 at 18:33
  • @steeldriver inded its faster – EdiD Feb 23 '16 at 18:35

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.