我在我的perl
腳本中使用此sed
單線程。然而,有沒有一種方法(我確信有)在Perl中做同樣的工作?將sed單線轉換爲perl
這裏是我的文件:
$ cat all_log1.txt
Looking into the table etl_f_gl_balance
# of -1 values in etl_f_gl_balance.row_key:
0
# of -1 values in etl_f_gl_balance.ledger_key:
1020
# of -1 values in etl_f_gl_balance.gl_account_key:
1020
# of -1 values in etl_f_gl_balance.legal_entity_key:
1020
# of -1 values in etl_f_gl_balance.cost_center_key:
995
# of -1 values in etl_f_gl_balance.natural_account_key:
1020
# of -1 values in etl_f_gl_balance.posting_period_fiscal_key:
5
# of -1 values in etl_f_gl_balance.posting_period_key:
5
而且我想下面的輸出,這裏是我的sed
解決方案:
$ sed ':a; N; $!ba; s/:\n/: /g' all_log1.txt
Looking into the table etl_f_gl_balance
# of -1 values in etl_f_gl_balance.row_key: 0
# of -1 values in etl_f_gl_balance.ledger_key: 1020
# of -1 values in etl_f_gl_balance.gl_account_key: 1020
# of -1 values in etl_f_gl_balance.legal_entity_key: 1020
# of -1 values in etl_f_gl_balance.cost_center_key: 995
# of -1 values in etl_f_gl_balance.natural_account_key: 1020
# of -1 values in etl_f_gl_balance.posting_period_fiscal_key: 5
# of -1 values in etl_f_gl_balance.posting_period_key: 5
目前,我沒有能夠得到它完成無論我使用哪種正則表達式組合,都使用perl。因此,我最終在我的perl
腳本中調用了sed
命令。
我不是在尋找一個Perl腳本,而是一個班輪。
謝謝。
那麼你到目前爲止嘗試過什麼? 'perl -pe's /:\ n /:/''不起作用? – amon
我不會發布輸出,但's2p':a; N; !$ BA; s \:\ n /:/ g''很有趣:['s2p' - sed to perl translator](http://man.cx/s2p) –
FWIW,你原來的'sed'命令可以簡化爲'' 1! {N; s /:\ n /:/ g}''或''/ ^#/ {N; s /:\ n /:/ g}'' –