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.

有帮助吗?

解决方案

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.

其他提示

var=$(awk -F'=' '/no_of_count/ {print $2}')
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top