I want to print the whole line with specific column started count variable in text.
1 101010 101010 4.0001 my home
2 101010 101010 5.0001 my home
3 101010 101010 6.0001 my home
4 101010 101010 7.0001 my home
count=4
awk -v cnt="$count" '$4 ~ /^[cnt]\./' file.log
1 101010 101010 4.0001 my home
Please tell me the wrong point of my script.
You need NOT to use awk variable in a literal regexp, use int function here to convert 4th field as interger and then compare it directly with variable like:
count="4"
awk -v cnt="$count" 'int($4)==cnt' Input_file
Explanation: First passing shell variable count to cnt as an awk variable. Then using int function on 4th field to get only integer part eg--> from 4.0001 to 4 to make an exact comparison with cnt and once its equal it will print that line.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With