如何删除CRLF空白行

时间:2017-08-22 14:32:40

标签: batch-file sed

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

我如何sed / awk / TR包含CR LF且没有文字的空白行?我已经在下面的每一行添加了返回,以向您展示它在Notepad ++中的外观。

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

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>

1 个答案:

答案 0 :(得分:0)

sed -i“s / \ r //”test.log将修复CR CRLF的问题