I am using this sed
one-liner in my perl
script. However, is there a way (I am sure there is) to do the same job in perl?
Here is my file:
$ 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
And I want the output as below and here is my sed
solution:
$ 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
At the moment, I am not able to get it done in perl no matter what combination of regex I use. And hence, I ended up calling this sed
command in my perl
script.
I am not looking for a perl script, but rather a one-liner.
Thanks.
This perl one-liner should work:
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With