Text Processing with a line break


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Text Processing with a line break
# 1  
Old 03-01-2011
Text Processing with a line break

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.
Code:
>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 "_".
Code:
_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.

Last edited by Franklin52; 03-01-2011 at 09:20 AM.. Reason: Please use code tags
# 2  
Old 03-01-2011
Try:
Code:
perl -0pe 's/\n(?!_)(?!$)//g' file

# 3  
Old 03-01-2011
Text Processing with a line break

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
Code:
sed -e :a -e '$!N;s/\n //;ta' -e 'P;D'

but it gives the same output as below.
Code:
>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


Last edited by Franklin52; 03-01-2011 at 09:49 AM.. Reason: Please use code tags
# 4  
Old 03-01-2011
Try:
Code:
perl -lp0e 's/\n(?!_)//g' file

If "_" means TAB character, then try this:
Code:
perl -lp0e 's/\n(?!\t)//g' file


Last edited by bartus11; 03-01-2011 at 09:53 AM..
# 5  
Old 03-01-2011
Text Processing with a line break

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
# 6  
Old 03-01-2011
Code:
 
awk '{printf "%s ",$0 ;if($0~/[0-9]$/){print ""}}' inputfile

# 7  
Old 03-01-2011
Code:
perl -lp0e 's/\n(?!  _)//g' file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to break the line to the one above?

Hello everyone! I'm trying to make the below file1 look like file2, can anyone help? Basically I just hit backspace on every line that starts with a number. Thanks! file1: THIS#IS-IT1 4 THIS#IS-IT2 3 THIS#IS-IT3 2 THIS#IS-IT4 1 Result > file2: (4 Replies)
Discussion started by: demmel
4 Replies

2. Programming

awk processing / Shell Script Processing to remove columns text file

Hello, I extracted a list of files in a directory with the command ls . However this is not my computer, so the ls functionality has been revamped so that it gives the filesizes in front like this : This is the output of ls command : I stored the output in a file filelist 1.1M... (5 Replies)
Discussion started by: ajayram
5 Replies

3. UNIX for Dummies Questions & Answers

Remove Line Break VI

I'm trying to make a script that says echo This is the date: I did this echo This is the date: date and it worked. But I need them both on the same line. And putting date on the echo line doesn't work. Is there a way to do so? (1 Reply)
Discussion started by: bbowers
1 Replies

4. UNIX for Dummies Questions & Answers

VI Line Break?

So I'm in a Unix class and our assignment was to go into VI and write a script to make this file tree. At the end of it, I'd like it to echo "This is the file tree you've created" then a line break, then . But I'm not sure as to who to do it. Is there a way for when I run it (./filesystem), the... (4 Replies)
Discussion started by: bbowers
4 Replies

5. Shell Programming and Scripting

Line break on word

I have a file that contains the following: ^field LINE_1 data ^field LINE_2 data ^field LINE_3 data ^field LINE_4 data ^field LINE_5 data ... And im looking to do a line break at the end of the number before the text to make it look like this ^field LINE_1 ... (11 Replies)
Discussion started by: darbs121
11 Replies

6. Shell Programming and Scripting

Add line break for each line in a file

I cannot seem to get this to work.. I have a file which has about 100 lines, and there is no end of line (line break \n) at the end of each line, and this is causing problem when i paste them into an application. the file looks like this this is a test that is a test balblblablblhblbha... (1 Reply)
Discussion started by: fedora
1 Replies

7. Shell Programming and Scripting

BASH: Break line, read, break again, read again...

...when the lines use both a colon and commas to separate the parts you want read as information. The first version of this script used cut and other non-Bash-builtins, frequently, which made it nice and zippy with little more than average processor load in GNOME Terminal but, predictably, slow... (2 Replies)
Discussion started by: SilversleevesX
2 Replies

8. Shell Programming and Scripting

Help to remove line break

My requirement is to read the csv file and need to remove if any line break in it. sample data: Row1: "Oslo, Symra kino",Oslo,130-7,Symra 1,130-7-91Row2:"Tønsberg, Brygga Kino SF",Tønsberg,202-1.Tønsberg SF 4,202-1-4 Expected data: Row1: "Oslo, Symra kino",Oslo,130-7,Symra... (4 Replies)
Discussion started by: cnraja
4 Replies

9. Shell Programming and Scripting

awk, perl Script for processing a single line text file

I need a script to process a huge single line text file: The sample of the text is: "forward_inline_item": "Inline", "options_region_Australia": "Australia", "server_event_err_msg": "There was an error attempting to save", "Token": "Yes", "family": "Family","pwd_login_tab": "Enter Your... (1 Reply)
Discussion started by: hmsadiq
1 Replies

10. Shell Programming and Scripting

TO break a line

hi All, Have a doubt in ksh..Am not familiar with arrays but i have tried out a script.. plzzzzz correct me with the script My i/p File is: (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP) (Host = 192.168.2.2) (Port = 1525) ) ) (CONNECT_DATA = (SID = TESTDB1) ) ) ... (7 Replies)
Discussion started by: aajan
7 Replies
Login or Register to Ask a Question