awk使用正则精确匹配
[root@localhost home]# cat file 5001][YRSD5-1][YRSD5-1-2][0203008400028411] 010102 5001][YRSD7-1][YRSD7-1-2][0203008400028411] 010102 5001][YRSD5-1][YRSD5-1-20][14030084000286E7] 010101 5001][YRSD7-1][YRSD7-1-3][03030084000285C0] 010102 5001][YRSD5-1][YRSD5-1-21][1503008400028736] 010101 5001][YRSD7-1][YRSD7-1-4][0403008400028477] 010101 5002][YRSD7-2][YRSD7-2-22][16030010000f072C] 000000 5001][YRSD5-1][YRSD5-1-23][17030010000f06FD] 001A00 5002][YRSD7-2][YRSD7-2-23][17030010000f06FD] 000000 5001][YRSD5-1][YRSD5-1-24][18030010000f0602] 004900 5002][YRSD7-2][YRSD7-2-24][180300380004C7CD] 000000 5002][YRSD7-2][YRSD7-2-25][19030084000287FA] 010102 5001][YRSD7-1][YRSD7-1-9][0903000800078482] 000001 5002][YRSD5-2][YRSD5-2-35][23030084000282A0] 010101 5001][YRSD5-1][YRSD5-1-26][1A030084000287C9] 010101 5002][YRSD5-2][YRSD5-2-36][240300380004C2F1] 000000 5002][YRSD5-2][YRSD5-2-37][25030084000282C6] 010101 5001][YRSD5-1][YRSD5-1-28][1C030010000f0786] 011301 5001][YRSD5-1][YRSD5-1-29][1D030010000f0657] 000000 5002][YRSD5-2][YRSD5-2-39][270300380004C2C2] 000000 5002][YRSD2-2][YRSD2-2-23][17030084000286D4] 010102 5001][YRSD5-1][YRSD5-1-4][040300080007859F] 00003E 5002][YRSD2-2][YRSD2-2-24][180300840002862B] 010102 5001][YRSD5-1][YRSD5-1-4][0403008400028477] 010101 5001][YRSD2-1][YRSD2-1-6][06030010000f05BC] 000700
想精确匹配最长列文本,最长列中有部分包含0300840002字符,使用awk的if语句
awk -F'\\]|\\[' '{if($7~/^..0300840002....$/)print $7}' file
.表示任意一个字符,而且要配合^$,不然会有贪婪匹配
"世界上只有一种真正的英雄主义,就是认清了生活的真相后,还依然执着地热爱它。"
——罗曼·罗兰