Hi all;
I'm stuck with this simple awk script,i need to group the lines which the position of 28 length 3 (if the line not starts with 0)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:
sort -t" " -rk2.12,2.14 FileLoad.txt |awk '
/^1/ { sub(/1/, "2") }
/^3/ { saved = $0 }
/^0/ { $NF = ($NF FS saved) }
{ x[FNR] = $0 }
END{
if (substr(x[FNR],1,1)=="0")
print x[FNR]
if(substr(x[j],1,1)!="0" && substr(x[j],28,3)=="688")
{
print 1
for (j=1; j<=FNR; j++)
if(substr(x[j],1,1)!="0" && substr(x[j],28,3)=="688")
print x[j]
}
if(substr(x[j],1,1)!="0" && substr(x[j],28,3)!="688")
{
print 1
for (j=1; j<=FNR; j++)
if(substr(x[j],1,1)!="0" && substr(x[j],28,3)!="688")
print x[j]
}
}'
After execute the script,the output shown:
040171011140820070000000009650244002933170003000000075272
1
2H912279980109 0108200700009965787889890090uyk
2F921338300506 010820070000198676767675645shdjd
can anyone help me to figure out?tq in advance