Dear Masters,
Need your help to process the below file named "breakline". At some places the rows are broken into two lines [for exp: for _sec-authentication-domain and _sec-authentication-system] and each rows starts with a tab space.
>cat breakline
_Index 187 18.4K 92 137 100 190 1.0 3.3
_Index-Field 365 26.7K 74 76 75 365 1.0 2.5
_KeyEvent 0 0.0B 0 0 0 0 0.0 0.0
_sec-authentication-domain
0 0.0B 0 0 0 0 0.0 0.0
_sec-authentication-system
0 0.0B 0 0 0 0 0.0 0.0
_sec-granted-role 0 0.0B 0 0 0 0 0.0 0.0
_sec-granted-role-condition
0 0.0B 0 0 0 0 0.0 0.0
_sec-role 0 0.0B 0 0 0 0 0.0 0.0
So if you can help me to get the output [as shown below]where such type of line breaks should be resolved into a single line. I mean $1 field should be starting with "_".
_Index 187 18.4K 92 137 100 190 1.0 3.3
_Index-Field 365 26.7K 74 76 75 365 1.0 2.5
_KeyEvent 0 0.0B 0 0 0 0 0.0 0.0
_sec-authentication-domain 0 0.0B 0 0 0 0 0.0 0.0
_sec-authentication-system 0 0.0B 0 0 0 0 0.0 0.0
_sec-granted-role 0 0.0B 0 0 0 0 0.0 0.0
_sec-granted-role-condition 0 0.0B 0 0 0 0 0.0 0.0
_sec-role 0 0.0B 0 0 0 0 0.0 0.0
Thanks for your reply.
Try:
perl -0pe 's/\n(?!_)(?!$)//g' file
I tried your command but I got the output as below:
All rows are getting concatenated instead of the rows that are broken into two rows. I searched the net and found something as
sed -e :a -e '$!N;s/\n //;ta' -e 'P;D'
but it gives the same output as below.
>perl -0pe 's/\n(?!_)(?!$)//g' breakline
_Index 187 18.4K 92 137 100 190 1.0 3.3 _Index-Field 365 26.7K 74 76 75 365 1.0 2.5 _KeyEvent 0 0.0B 0 0 0 0 0.0 0.0 _sec-authentication-domain 0 0.0B 0 0 0 0 0.0 0.0 _sec-authentication-system 0 0.0B 0 0 0 0 0.0 0.0 _sec-granted-role 0 0.0B 0 0 0 0 0.0 0.0 _sec-granted-role-condition 0 0.0B 0 0 0 0 0.0 0.0 _sec-role 0 0.0B 0 0 0 0 0.0 0.0
Try:
perl -lp0e 's/\n(?!_)//g' file
If "_" means TAB character, then try this:
perl -lp0e 's/\n(?!\t)//g' file
Getting the same output:
FYI, I've attached the text file which are to be processed.
>perl -0ple 's/\n(?!_)(?!$)//g' breakline
_Index 187 18.4K 92 137 100 190 1.0 3.3 _Index-Field 365 26.7K 74 76 75 365 1.0 2.5 _KeyEvent 0 0.0B 0 0 0 0 0.0 0.0 _sec-authentication-domain 0 0.0B 0 0 0 0 0.0 0.0 _sec-authentication-system 0 0.0B 0 0 0 0 0.0 0.0 _sec-granted-role 0 0.0B 0 0 0 0 0.0 0.0 _sec-granted-role-condition 0 0.0B 0 0 0 0 0.0 0.0 _sec-role 0 0.0B 0 0 0 0 0.0 0.0
xoops
March 1, 2011, 8:55am
6
awk '{printf "%s ",$0 ;if($0~/[0-9]$/){print ""}}' inputfile
perl -lp0e 's/\n(?! _)//g' file
nawk 'ORS=(/[0-9]$/)?RS:FS' myFile
Great !!!
It worked now.
Thanks you all for your quick reply.