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 Answer 1

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

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .