001、
[root@localhost test]# cat b.txt ## 测试数据 0001 20081223efs333kjfdj EREADFASDLKJCV 0002 20081208djfks2288daa JDKFJALSDJFsddf 0003 20081208efskjfdj EREADFASDLKJCV 0004 20081211djfksdaa1234 JDKFJALSDJFsddf [root@localhost test]# awk '{sub("[0-9]", "", $2); print $0}' b.txt ## 匹配首个数字 0001 0081223efs333kjfdj EREADFASDLKJCV 0002 0081208djfks2288daa JDKFJALSDJFsddf 0003 0081208efskjfdj EREADFASDLKJCV 0004 0081211djfksdaa1234 JDKFJALSDJFsddf [root@localhost test]# awk '{sub("[0-9]+", "", $2); print $0}' b.txt ## 匹配首个连续的数字 0001 efs333kjfdj EREADFASDLKJCV 0002 djfks2288daa JDKFJALSDJFsddf 0003 efskjfdj EREADFASDLKJCV 0004 djfksdaa1234 JDKFJALSDJFsddf
。
002、
[root@localhost test]# cat b.txt ## 测试数据 0001 20081223efs333kjfdj EREADFASDLKJCV 0002 20081208djfks2288daa JDKFJALSDJFsddf 0003 20081208efskjfdj EREADFASDLKJCV 0004 20081211djfksdaa1234 JDKFJALSDJFsddf [root@localhost test]# awk '{sub(/[0-9]/, "", $2); print $0}' b.txt ## 第二行匹配数个数字 0001 0081223efs333kjfdj EREADFASDLKJCV 0002 0081208djfks2288daa JDKFJALSDJFsddf 0003 0081208efskjfdj EREADFASDLKJCV 0004 0081211djfksdaa1234 JDKFJALSDJFsddf [root@localhost test]# awk '{sub(/[0-9]+/, "", $2); print $0}' b.txt ## 匹配第二行首个连续的数字 0001 efs333kjfdj EREADFASDLKJCV 0002 djfks2288daa JDKFJALSDJFsddf 0003 efskjfdj EREADFASDLKJCV 0004 djfksdaa1234 JDKFJALSDJFsddf
。
标签:JDKFJALSDJFsddf,匹配,数字,EREADFASDLKJCV,##,首个,test,txt,localhost From: https://www.cnblogs.com/liujiaxin2018/p/18504104