【发布时间】:2014-05-08 21:20:21
【问题描述】:
我在我的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/: /'没有用吗? -
我不会发布输出,但
s2p ':a; N; $!ba; s/:\n/: /g'很有趣:s2p- sed to perl translator -
FWIW,您原来的
sed命令可以简化为'1 ! {N; s/:\n/: /g}'或'/^#/ {N; s/:\n/: /g}'