我有grep输出:
Nov 07 16:03:23 SA1789 miner[1397]: GPU4 not responding
Nov 07 16:03:23 SA1789 miner[1397]: Thread(s) not responding. Restarting.
Nov 07 16:02:25 SA0888 miner[1505]: GPU12 not responding
Nov 07 16:02:25 SA0888 miner[1505]: Thread(s) not responding. Restarting.
Nov 07 16:04:17 SA0888 miner[1505]: GPU12 not responding
Nov 07 16:04:17 SA0888 miner[1505]: Thread(s) not responding. Restarting.
想要得到这个:
Nov 07 16:03:23 ==> GPU4
Nov 07 16:02:25 ==> GPU12
Nov 07 16:04:17 ==> GPU12
awk '/GPU/{s=index($7,":"); $7=substr($7,s+1,length($7)-s-1); print $1" "$2" "$3" => "$7}'
很抱歉,我只是菜鸟,只需要专家的快速解决方案即可。
答案 0 :(得分:4)
简单的awk
表达式:
$ awk '/GPU/{ print $1, $2, $3, "==>", $6 }' file
Nov 07 16:03:23 ==> GPU4
Nov 07 16:02:25 ==> GPU12
Nov 07 16:04:17 ==> GPU12