I'm stuck with this simple awk script,i need to group the lines which the position of 28 length 3 that contains "688" into 1 group and other than "688" into another group. My problem is the script only read other than "688" and ignores the lines which contains "688".
The file look like this:
040171011140820070000000009650244002933170003000000075272
1F921338300506 01082007000688jkjddiwe02499834fg
1F921338300506 010820070000198676767675645shdjd
1H912279980109 0108200700009965787889890090uyk
1H912279980109 01082007000688djjdfieuireurireiro
I used this script to group the lines:
After execute the script,the output shown:
040171011140820070000000009650244002933170003000000075272
1
2H912279980109 0108200700009965787889890090uyk
2F921338300506 010820070000198676767675645shdjd
There are 2 lines contain 688
1F921338300506 01082007000688jkjddiwe02499834fg
1H912279980109 01082007000688djjdfieuireurireiro
There are 3 lines not contain 688
040171011140820070000000009650244002933170003000000075272
1F921338300506 010820070000198676767675645shdjd
1H912279980109 0108200700009965787889890090uyk
code:
nawk '{
temp=substr($0,27,3)
if (temp=="688")
{
m++
a[m]=$0
}
else
{
n++
oth[n]=$0
}
}
END{
print "There are "m" lines contain 688"
for (i=1;i<=m;i++)
print a
print""
print""
print "There are "n" lines not contain 688"
for (i=1;i<=n;i++)
print oth
}' filename