sla*_*fer 2 regex bash perl sed
我sed在我的perl剧本中使用这个单行程.但是,有没有办法(我确定有)在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
Run Code Online (Sandbox Code Playgroud)
我想要输出如下,这是我的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
Run Code Online (Sandbox Code Playgroud)
目前,无论我使用什么样的正则表达式组合,我都无法在perl中完成它.因此,我最终sed在我的perl脚本中调用了这个命令.
我不是在寻找一个perl脚本,而是一个单行.
谢谢.
这个perl单行应该工作:
perl -pe 's/:\n$/: /' file
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
Run Code Online (Sandbox Code Playgroud)