Reputation: 23502
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.
Upvotes: 4
Views: 2686
Reputation: 11116
This one will take backup of current file and update it:
perl -i.bak -pe 's/\n$/ /g if /^#/gm' all_log1.txt
If you want to have output in screen, then use this one:
perl -pe 's/\n$/ /g if /^#/gm' all_log1.txt
Upvotes: 2
Reputation: 785108
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
Upvotes: 9