In unix/awk code
Essentially, I need to iterate through the file (data1.txt) and count the number of times the substr($0,29,2) of each line of the file == "04".
data1.txt:
6597243042 20160305001100003140152852153019000127000200
6597243042 20160305001100003140170306190306020000000200
6597243042 20160305001100003140170552190552020000000200
6597243042 20160305001100003140201430201543000113000400
6592311319 20160305041100003460072719072839000120001200
6592311319 20160305041100003460072927072952000025001200
In this case only 2 lines of the file (data1.txt) fulfill the condition (substr($0,29,2)=="04")
I am stuck at finding a way to do so
Below is my unix/awk code
Filename="def"
file="data1.txt"
#awk '{count1=0}'
while IFS= read line
do
awk '{ if (substr($0,29,2)=="04") {print substr($0,29,4)}}'
done <"$file"
How can I count this?
$linein thewhileloop. And the loop wouldn't be needed either, use just AWK:awk 'substr($0,29,2)=="04" {print}' file(again, in your file no line matches such condition).