如何删除 CRLF 空行



我有一个有空格的日志文件,我想删除它们,但是,在某些情况下,实际的日志行以 CR 结尾,有些以 CR LF 结尾。

如何对有 CR LF 但没有文本的空行进行 sed/awk/TR?我在下面的每一行中添加了返回,以向您展示它在记事本++中的外观。

我尝试了以下命令,但是,在某些情况下,它会从其他日志行中删除最后的章程。

sed -i "s/.$//" %Logs%%DIR1%/%FILENAME1

把这个

08-22 08:54:53.612 I/SystemServer(  760): StartUserManagerServic
08-22 08:54:53.612 I/SystemServiceManager(  760): Starting com.android.server.pm.UserManagerService$LifeCycl
08-22 08:54:53.613 I/SystemServer(  760): InitAttributerCach

进入这个

08-22 08:54:53.612 I/SystemServer(  760): StartUserManagerService
08-22 08:54:53.612 I/SystemServiceManager(  760): Starting com.android.server.pm.UserManagerService$LifeCycle
08-22 08:54:53.613 I/SystemServer(  760): InitAttributerCache

示例:添加了 CRLF 的日志。尝试在不切断实际日志行的情况下删除空格

08-22 09:13:42.018 D/TESTAPP( 7560): <<< Server Application info >>> <CR><LF>
08-22 09:13:42.018 D/TESTAPP( 7560): Name: Subscription<CR><LF>
08-22 09:13:42.018 D/TESTAPP( 7560): Package: com.bla.bla2<CR><LF>
08-22 09:13:42.018 D/TESTAPP( 7560): Version Name: 1.0.32.47<CR><LF>
08-22 09:13:42.018 D/TESTAPP( 7560): Version Code: 32<CR>
<CR><LF>
08-22 09:13:42.019 I/TESTAPP( 7560): (95): Upgrade for Subscription is not available<CR>
<CR><LF>
08-22 09:13:42.020 W/TESTAPP( 7560): (95): Unable to get the information of ccom.bla.bla as it is not installed<CR>
<CR><LF>
08-22 09:13:42.021 W/TESTAPP( 7560): (95): Unable to get the information of com.bla.bla as it is not installed<CR>
<CR><LF>
08-22 09:13:42.023 W/TESTAPP( 7560): (95): Unable to get the information of com.bla.bla<CR>

sed -i "s/\r//" test.log 将解决您有 CR CRLF 的问题

最新更新