Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use awk to extract value from a line

Tags:

bash

sed

awk

I have these two lines within a file:

<first-value system-property="unique.setting.limit">3</first-value>
<second-value-limit>50000</second-value-limit>

where I'd like to get the following as output using awk or sed:

3    
50000

Using this sed command does not work as I had hoped, and I suspect this is due to the presence of the quotes and delimiters in my line entry.

sed -n '/WORD1/,/WORD2/p' /path/to/file

How can I extract the values I want from the file?

like image 774
qu1x0tc Avatar asked Mar 18 '23 19:03

qu1x0tc


1 Answers

awk -F'[<>]' '{print $3}' input.txt

input.txt:

<first-value system-property="unique.setting.limit">3</first-value>
<second-value-limit>50000</second-value-limit>

Output:

3
50000
like image 196
a5hk Avatar answered Mar 21 '23 08:03

a5hk