我需要帮助删除两个空白行之前的文本。
任何人都可以通过SED帮助解决这个问题吗?
示例:(我的日志文件) 行:“%%%% Info | Date:...”
来源:
%%%% Info | Date: (11-02-18)-Day=042 - %%%%
OLD: android-902 (11-02-18 02:30)
Wi-Fi up - USB (11-02-18 03:21:21)
%%%% - Info | Date: (12-02-18)-Day=043 - %%%%
Wi-Fi up - USB (12-02-18 07:17:02)
Smart Connected (12-02-18 10:19)
%%%% - Info | Date: (13-02-18)-Day=044 - %%%%
%%%% - Info | Date: (14-02-18)-Day=045 - %%%%
%%%% - Info | Date: (15-02-18)-Day=046 - %%%%
%%%% - Info | Date: (16-02-18)-Day=047 - %%%%
Wi-Fi up - USB (16-02-18 06:32:24)
输出:
%%%% Info | Date: (11-02-18)-Day=042 - %%%%
OLD: android-902 (07-02-18 02:30)
Wi-Fi up - USB (07-02-18 03:21:21)
%%%% - Info | Date: (12-02-18)-Day=043 - %%%%
Wi-Fi up - USB (12-02-18 07:17:02)
Smart Connected (12-02-18 10:19)
%%%% - Info | Date: (16-02-18)-Day=047 - %%%%
Wi-Fi up - USB (16-02-18 06:32:24)
提前致谢。
答案 0 :(得分:0)
awk
是一个非常强大的工具,但它不是用于多行处理的最佳工具,只需使用以下$ awk 'BEGIN{RS="%%%%[^%]+%%%%\n\n\n"}{printf "%s",$0}' input.log
%%%% Info | Date: (11-02-18)-Day=042 - %%%%
OLD: android-902 (11-02-18 02:30)
Wi-Fi up - USB (11-02-18 03:21:21)
%%%% - Info | Date: (12-02-18)-Day=043 - %%%%
Wi-Fi up - USB (12-02-18 07:17:02)
Smart Connected (12-02-18 10:19)
%%%% - Info | Date: (16-02-18)-Day=047 - %%%%
Wi-Fi up - USB (16-02-18 06:32:24)
解决方案即可完成任务。
RS="%%%%[^%]+%%%%\n\n\n"
说明:
awk
是ORS
将用于查找每条记录的记录分隔符,因为您使用默认\n
这些字段只会从输出中删除并替换通过+-----------------+--------+
| Project | Budget |
+-----------------+--------+
| P1200 | 150 |
| P1400 | 200 |
| L3 Program 3 | 350 |
| P1100 | 250 |
| P1300 | 150 |
| L3 Program 2 | 400 |
| L2 Initiative 2 | 750 |
| P2200 | 300 |
| P2400 | 200 |
| P2600 | 300 |
| L3 Program 1 | 800 |
| L2 Initiative 1 | 800 |
| L1 Division | 1550 |
+-----------------+--------+