Multiple line break

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Multiple line break
# 1  
Old 08-13-2011
Multiple line break

We had an issue with one file. Each line in the file is a record in which there will be 6 fields each separated by ; Problem is some lines are broken into pieces.
instead of a;b;c;d;e;f
I have filtered out all the broken lines from the original file and wrote to new file.
I need a logic to join these line when the filed count reach 6
I found one method like first joining all lines then breaking them when it reaches 6 fields. But the breaking portion is not working, Can any one please help
perl -0lne 's/\n//g file -- i used this one to oin all the lines...
# 2  
Old 08-13-2011
perl -0777 -lpe 's/;\n/;/g;' INPUTFILE

# 3  
Old 08-13-2011
But this only deletes the ';'+ 'newlinecharecter', but not checking if it reach 7 field and break the line again..
i mean if the file is
then the outpt should be
# 4  
Old 08-13-2011
Why some your lines ends with ";", others not? Why in your first post the required output lines do not end with ";" and in your second they end?

Change all your newlines to ";", then change double ";;" to ";" , split the whole file on ";" and output records in a loop.

And give real examples if you want get a real help.
# 5  
Old 08-13-2011
Not perl, but give this code a try:
{ sed 's/;/\n/g' | sed '/^$/d' | awk '{s=s$0";"}!(NR%7){print s;s=""}END{if(s)print s}';} < your_file

Last edited by tukuyomi; 08-13-2011 at 11:50 AM.. Reason: Code arrangements
# 6  
Old 08-13-2011
perl -F'[;\n]' -alne '
push @a, @F;
print join(";", splice @a, 0, 7), ";" if @a >=7;
END { print (join ";", splice @a, 0, 7), ";" if @a }

Last edited by yazu; 08-13-2011 at 10:55 PM.. Reason: corrected
# 7  
Old 08-13-2011
awk -F\; '{for(i=0;++i<=NF;){if($i){$i=$i;if(c<=7){printf $i FS;c++};if(c==7){printf RS;c=x}}}}' file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Break on record with multiple with userid

I'm using the unix terminal in Mac osx yosemite. I have a file 1;2015p;2014r;2013r;2013p 2;2013p;2013r;2012g 3;2013g 4;2015g;2014g;2013r;2012s;2011s The first column is the userid, the second column is each event. I'd like a separate record for each event. 1 2015p 1 2014r 1 ... (5 Replies)
Discussion started by: Nataliemf
5 Replies

2. Shell Programming and Scripting

Break line content into multiple lines using delimiter

I need to break the line after every 3rd semi colon(;) using Unix shell scripting Input.txt ABC;DEF;JHY;LKU;QWE;BVF;RGHY; Output.txt ABC;DEF;JHY; LKU;QWE;BVF; RGHY; (1 Reply)
Discussion started by: meet_calramz
1 Replies

3. 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

4. Shell Programming and Scripting

break from a single list into multiple columns

Hi Guys, I am prety new to the hell scripting world. I am running some grep/cut commands and extracting from a csv file into a list. But the final product I need is that the whole list that I now have has to be broken and separated into columns. Say what I now have extracted is a list of... (6 Replies)
Discussion started by: h_rishi
6 Replies

5. Shell Programming and Scripting

Line Break problem

Hi All, Please can you advise/help on the below issue i did a bcp out of a table, it is having problem of line break such that one line is getting broken in two lines for many records. eg Correct format Line 1: - 000f00000bfe2c2c 000218310300000000GBP GBP 734654 10970.35 ... (3 Replies)
Discussion started by: mad_man12
3 Replies

6. 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

7. 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

8. 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

9. 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

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 = (Port = 1525) ) ) (CONNECT_DATA = (SID = TESTDB1) ) ) ... (7 Replies)
Discussion started by: aajan
7 Replies
Login or Register to Ask a Question