質問

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