문제

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