删除日志文件换行符

问题描述 投票:-1回答:1

我只是想后“ParNew”字符串,删除换行符。

即ParNew的下一行应ParNew线合并。

2019-01-11T09:24:17.063+0800: 519253.299: [GC 519253.300: [ParNew
: 846970K->7882K(943744K), 0.0466880 secs] 74546294K->73707206K(75392640K), 0.0479230 secs] [Times: user=0.77 sys=0.00, real=0.05 secs] 
- age   3:        360 bytes,    6983240 total
- age   2:       1680 bytes,    6982880 total
- age   1:    6981200 bytes,    6981200 total
Desired survivor size 53673984 bytes, new threshold 4 (max 4)
2019-01-11T09:24:16.645+0800: 519252.881: [GC 519252.882: [ParNew
: 846986K->8058K(943744K), 0.0470990 secs] 74547818K->73708889K(75392640K), 0.0483330 secs] [Times: user=0.78 sys=0.00, real=0.05 secs] 
- age   4:        512 bytes,    7107392 total
- age   2:       1968 bytes,    7106880 total
- age   1:    7104912 bytes,    7104912 total
regex text-files
1个回答
1
投票

Perl的允许多行正则表达式。试试这个行:

perl -ne 's/ParNew\n/ParNew/g; print;' your_file.txt

结果:

2019-01-11T09:24:17.063+0800: 519253.299: [GC 519253.300: [ParNew: 846970K->7882K(943744K), 0.0466880 secs] 74546294K->73707206K(75392640K), 0.0479230 secs] [Times: user=0.77 sys=0.00, real=0.05 secs] 
- age   3:        360 bytes,    6983240 total
- age   2:       1680 bytes,    6982880 total
- age   1:    6981200 bytes,    6981200 total
Desired survivor size 53673984 bytes, new threshold 4 (max 4)
2019-01-11T09:24:16.645+0800: 519252.881: [GC 519252.882: [ParNew: 846986K->8058K(943744K), 0.0470990 secs] 74547818K->73708889K(75392640K), 0.0483330 secs] [Times: user=0.78 sys=0.00, real=0.05 secs] 
- age   4:        512 bytes,    7107392 total
- age   2:       1968 bytes,    7106880 total
- age   1:    7104912 bytes,    7104912 total

这里:

  • -e允许要执行的命令(图案取代)
  • -n嵌入在一个隐含循环的命令,该命令将遍历每行从stdin得到
© www.soinside.com 2019 - 2024. All rights reserved.