Question

I need to read a value from a file in the following manner.

input log file:

some log report data
no_of_count = "45"
some log report data

Now i want to read the line no_of_count = "45" into shell script and get that 45 into a variable
Is there any command to do that.

Was it helpful?

Solution

awk one-liner:

awk -F '[ ="]+' '$1=="no_of_count"{print $2}' file
45

Explanation: This awk uses regex in field separator as space OR = OR double quote. + quantifier in regex means 1 or more which makes awk to grab more than one of those characters as separators thus printing 45 in $2.

OTHER TIPS

var=$(awk -F'=' '/no_of_count/ {print $2}')
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top