假设我有一个日志文件或如下所示的文本文件
16 Dec 2014 11:20:00 [INFO] com.example.Test.java PlaneName: JetAirways360 This flight just cleaned up
16 Dec 2014 11:22:01 [INFO] com.example.Test.java PlaneName: JetAirways360 This flight is in queue
16 Dec 2014 11:23:02 [INFO] com.example.Test.java PlaneName: JetAirways360 This flight passengers loaded
16 Dec 2014 11:24:03 [INFO] com.example.Test.State.java PlaneName: JetAirways360 This flight ready to take off
16 Dec 2014 11:25:00 [INFO] com.example.Test.State.java PlaneName: JetAirways360 This flight took off
17 Dec 2014 11:25:00 [INFO] com.example.Test.java PlaneName: JetAirways360 This flight returned back
现在想象一下我这个日志文件已经完全填满了很多航班信息。听说要找到一个特定的航班信息。现在我想看看下面的细节
16 Dec 2014 11:20:00 This flight just cleaned up
16 Dec 2014 11:22:01 This flight is in queue
16 Dec 2014 11:23:02 This flight passengers loaded
16 Dec 2014 11:24:03 This flight ready to take off
16 Dec 2014 11:25:00 This flight took off
17 Dec 2014 11:25:00 This flight returned back
如何使用grep和sed命令执行此操作?是的。
最佳答案
这可能对你有用(gnu sed):
sed -rn '/JetAirWays360/s/(.{21}).{54}/\1/p' file
这会将文件的第一部分保存在反向引用中,并用它替换其余文件的一部分。
关于linux - 如何使用grep和sed打印多个String?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27512758/