0

我目前正在解析gcc类似的错误日志

main.c:5:1: warning: data definition has no type or storage class [enabled by default]
main.c:8:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘void’
main.c in function 'TryAdddition()'
main.c:24:1: warning: data definition has no type or storage class [enabled by default]
main.c:24:10: warning: data definition has no type or storage class [enabled by default] 

5,8,24,24 是发生错误或警告的行号。我需要用数字+10 替换这些数字,即: 15,18,34,34

然而,并非每一行都是错误或警告行。

4

1 回答 1

5

我想说awk这是这项工作的一个很好的工具。要将更改仅应用于errorwarning行:

$ awk '$4==" warning" || $4==" error"{$2+=10}1' FS=':' OFS=':' file
main.c:15:1: warning: data definition has no type or storage class [enabled by default]
main.c:18:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘void’
main.c in function 'TryAdddition()'
main.c:34:1: warning: data definition has no type or storage class [enabled by default]
main.c:34:10: warning: data definition has no type or storage class [enabled by default
于 2013-08-02T16:46:09.310 回答