Break lines that appear together


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Break lines that appear together
# 1  
Old 09-17-2014
Break lines that appear together

Hello to all

May you help me with a sed or awk script to fix the text below please.

I have a file where all lines should have 67 characters but from time to time 2 lines appear together like below.
* First column always has 15 characters
* Second column always has 32 characters
* 3rd, 4th and 5th columns always has 1 character
Code:
123458888233679  XYZWRTED849ABCDE03E0FD66CE356D7B    8    9       7
123458888233682  XYZWRT68107ABCDEEA08EB6325B566BE    8    9       7
123458888233730  XYZWRT02FE2ABCDE521CC167A3256DD1    8    9       7123458888233732  XFSOIS0D8E3A3705699DC15D40D30AB9    8    9       7
123458888233762  XYZWRT2971CABCDEE257D00E3C856928    8    9       7
123458888233836  XYZWRTCBF82ABCDE7775DDAEFBD56394    8    9       7
123458888233871  XYZWRT493B9ABCDEDCF3C00266C568A2    8    9       7
123458888233883  XYZWRT869D5ABCDE41AD15F37E956720    8    9       7123458888233907  POSUSF6AAC016TI2A8E05C4FE49FE92C    8    9       7
123458888233937  XYZWRT5AFEEABCDEA37E9A1135356C73    8    9       7

The output would be:
Code:
123458888233679  XYZWRTED849ABCDE03E0FD66CE356D7B    8    9       7
123458888233682  XYZWRT68107ABCDEEA08EB6325B566BE    8    9       7
123458888233730  XYZWRT02FE2ABCDE521CC167A3256DD1    8    9       7
123458888233732  XFSOIS0D8E3A3705699DC15D40D30AB9    8    9       7
123458888233762  XYZWRT2971CABCDEE257D00E3C856928    8    9       7
123458888233836  XYZWRTCBF82ABCDE7775DDAEFBD56394    8    9       7
123458888233871  XYZWRT493B9ABCDEDCF3C00266C568A2    8    9       7
123458888233883  XYZWRT869D5ABCDE41AD15F37E956720    8    9       7
123458888233907  POSUSF6AAC016TI2A8E05C4FE49FE92C    8    9       7
123458888233937  XYZWRT5AFEEABCDEA37E9A1135356C73    8    9       7

Thanks in advance for any help.
# 2  
Old 09-17-2014
Lookup the manpage of fold...it'd do what you're looking for as there is no need for sed or awk...
# 3  
Old 09-17-2014
Hello shamrock,

It seems to work with fold, the issue is because there are some lines between blocks, fold does the job, only puts these other lines at the end.

Best regards
# 4  
Old 09-17-2014
Quote:
Originally Posted by Ophiuchus
Hello shamrock,

It seems to work with fold, the issue is because there are some lines between blocks, fold does the job, only puts these other lines at the end.

Best regards
So do you want them to immediately follow the line it is joined with? I am not sure what you mean by your last post as on my system it does the job...
Code:
$ cat file
123458888233679  XYZWRTED849ABCDE03E0FD66CE356D7B    8    9       7
123458888233682  XYZWRT68107ABCDEEA08EB6325B566BE    8    9       7
123458888233730  XYZWRT02FE2ABCDE521CC167A3256DD1    8    9       7123458888233732  XFSOIS0D8E3A3705699DC15D40D30AB9    8    9       7
123458888233762  XYZWRT2971CABCDEE257D00E3C856928    8    9       7
123458888233836  XYZWRTCBF82ABCDE7775DDAEFBD56394    8    9       7
123458888233871  XYZWRT493B9ABCDEDCF3C00266C568A2    8    9       7
123458888233883  XYZWRT869D5ABCDE41AD15F37E956720    8    9       7123458888233907  POSUSF6AAC016TI2A8E05C4FE49FE92C    8    9       7
123458888233937  XYZWRT5AFEEABCDEA37E9A1135356C73    8    9       7

$ fold -w 67 file
123458888233679  XYZWRTED849ABCDE03E0FD66CE356D7B    8    9       7
123458888233682  XYZWRT68107ABCDEEA08EB6325B566BE    8    9       7
123458888233730  XYZWRT02FE2ABCDE521CC167A3256DD1    8    9       7
123458888233732  XFSOIS0D8E3A3705699DC15D40D30AB9    8    9       7
123458888233762  XYZWRT2971CABCDEE257D00E3C856928    8    9       7
123458888233836  XYZWRTCBF82ABCDE7775DDAEFBD56394    8    9       7
123458888233871  XYZWRT493B9ABCDEDCF3C00266C568A2    8    9       7
123458888233883  XYZWRT869D5ABCDE41AD15F37E956720    8    9       7
123458888233907  POSUSF6AAC016TI2A8E05C4FE49FE92C    8    9       7
123458888233937  XYZWRT5AFEEABCDEA37E9A1135356C73    8    9       7


Last edited by shamrock; 09-17-2014 at 05:21 PM..
# 5  
Old 09-17-2014
Is this what you are after?
Longhand using OSX 10.7.5 default bash terminal...
This assumes that the length of first line is a constant throughout...
Also changed the end of the long lines to A from 7 to see where it is...
Code:
#!/bin/bash
# brk.sh
> /tmp/text
> /tmp/newtext
echo '123458888233679  XYZWRTED849ABCDE03E0FD66CE356D7B    8    9       7
123458888233682  XYZWRT68107ABCDEEA08EB6325B566BE    8    9       7
123458888233730  XYZWRT02FE2ABCDE521CC167A3256DD1    8    9       7123458888233732  XFSOIS0D8E3A3705699DC15D40D30AB9    8    9       7
123458888233762  XYZWRT2971CABCDEE257D00E3C856928    8    9       7
123458888233836  XYZWRTCBF82ABCDE7775DDAEFBD56394    8    9       7
123458888233871  XYZWRT493B9ABCDEDCF3C00266C568A2    8    9       7
123458888233883  XYZWRT869D5ABCDE41AD15F37E956720    8    9       7123458888233907  POSUSF6AAC016TI2A8E05C4FE49FE92C    8    9       A
123458888233937  XYZWRT5AFEEABCDEA37E9A1135356C73    8    9       7123458888233679  XYZWRTED849ABCDE03E0FD66CE356D7B    8    9       A
123458888233682  XYZWRT68107ABCDEEA08EB6325B566BE    8    9       7
123458888233730  XYZWRT02FE2ABCDE521CC167A3256DD1    8    9       7123458888233732  XFSOIS0D8E3A3705699DC15D40D30AB9    8    9       A
123458888233762  XYZWRT2971CABCDEE257D00E3C856928    8    9       7
123458888233836  XYZWRTCBF82ABCDE7775DDAEFBD56394    8    9       7
123458888233871  XYZWRT493B9ABCDEDCF3C00266C568A2    8    9       7
123458888233883  XYZWRT869D5ABCDE41AD15F37E956720    8    9       7123458888233907  POSUSF6AAC016TI2A8E05C4FE49FE92C    8    9       A
123458888233937  XYZWRT5AFEEABCDEA37E9A1135356C73    8    9       7123458888233679  XYZWRTED849ABCDE03E0FD66CE356D7B    8    9       A
123458888233682  XYZWRT68107ABCDEEA08EB6325B566BE    8    9       7
123458888233730  XYZWRT02FE2ABCDE521CC167A3256DD1    8    9       7123458888233732  XFSOIS0D8E3A3705699DC15D40D30AB9    8    9       A
123458888233762  XYZWRT2971CABCDEE257D00E3C856928    8    9       7
123458888233836  XYZWRTCBF82ABCDE7775DDAEFBD56394    8    9       7
123458888233871  XYZWRT493B9ABCDEDCF3C00266C568A2    8    9       7
123458888233883  XYZWRT869D5ABCDE41AD15F37E956720    8    9       7123458888233907  POSUSF6AAC016TI2A8E05C4FE49FE92C    8    9       A
123458888233937  XYZWRT5AFEEABCDEA37E9A1135356C73    8    9       7123458888233679  XYZWRTED849ABCDE03E0FD66CE356D7B    8    9       A
123458888233682  XYZWRT68107ABCDEEA08EB6325B566BE    8    9       7
123458888233730  XYZWRT02FE2ABCDE521CC167A3256DD1    8    9       7123458888233732  XFSOIS0D8E3A3705699DC15D40D30AB9    8    9       A
123458888233762  XYZWRT2971CABCDEE257D00E3C856928    8    9       7
123458888233836  XYZWRTCBF82ABCDE7775DDAEFBD56394    8    9       7
123458888233871  XYZWRT493B9ABCDEDCF3C00266C568A2    8    9       7
123458888233883  XYZWRT869D5ABCDE41AD15F37E956720    8    9       7123458888233907  POSUSF6AAC016TI2A8E05C4FE49FE92C    8    9       A
123458888233937  XYZWRT5AFEEABCDEA37E9A1135356C73    8    9       7123458888233679  XYZWRTED849ABCDE03E0FD66CE356D7B    8    9       A
123458888233682  XYZWRT68107ABCDEEA08EB6325B566BE    8    9       7
123458888233730  XYZWRT02FE2ABCDE521CC167A3256DD1    8    9       7123458888233732  XFSOIS0D8E3A3705699DC15D40D30AB9    8    9       A
123458888233762  XYZWRT2971CABCDEE257D00E3C856928    8    9       7
123458888233836  XYZWRTCBF82ABCDE7775DDAEFBD56394    8    9       7
123458888233871  XYZWRT493B9ABCDEDCF3C00266C568A2    8    9       7
123458888233883  XYZWRT869D5ABCDE41AD15F37E956720    8    9       7123458888233907  POSUSF6AAC016TI2A8E05C4FE49FE92C    8    9       A
123458888233937  XYZWRT5AFEEABCDEA37E9A1135356C73    8    9       7123458888233679  XYZWRTED849ABCDE03E0FD66CE356D7B    8    9       A
123458888233682  XYZWRT68107ABCDEEA08EB6325B566BE    8    9       7
123458888233730  XYZWRT02FE2ABCDE521CC167A3256DD1    8    9       7123458888233732  XFSOIS0D8E3A3705699DC15D40D30AB9    8    9       A
123458888233762  XYZWRT2971CABCDEE257D00E3C856928    8    9       7
123458888233836  XYZWRTCBF82ABCDE7775DDAEFBD56394    8    9       7
123458888233871  XYZWRT493B9ABCDEDCF3C00266C568A2    8    9       7
123458888233883  XYZWRT869D5ABCDE41AD15F37E956720    8    9       7123458888233907  POSUSF6AAC016TI2A8E05C4FE49FE92C    8    9       A
123458888233937  XYZWRT5AFEEABCDEA37E9A1135356C73    8    9       7' > /tmp/text
ifs_str="$IFS"
IFS="
"
# Assume all lines are the same length...
read line < /tmp/text
length=${#line}
while read line
do
	if [ ${#line} -eq $length ]
	then
		echo "$line" >> /tmp/newtext
	else
		echo "${line:0:$length}" >> /tmp/newtext
		echo "${line:$length:$length}" >> /tmp/newtext
	fi
done < /tmp/text
cat /tmp/newtext
IFS="$ifs_str"
exit 0

Results:-
Code:
Last login: Wed Sep 17 21:24:10 on ttys000
AMIGA:barrywalker~> chmod 755 brk.sh
AMIGA:barrywalker~> ./brk.sh
123458888233679  XYZWRTED849ABCDE03E0FD66CE356D7B    8    9       7
123458888233682  XYZWRT68107ABCDEEA08EB6325B566BE    8    9       7
123458888233730  XYZWRT02FE2ABCDE521CC167A3256DD1    8    9       7
123458888233732  XFSOIS0D8E3A3705699DC15D40D30AB9    8    9       7
123458888233762  XYZWRT2971CABCDEE257D00E3C856928    8    9       7
123458888233836  XYZWRTCBF82ABCDE7775DDAEFBD56394    8    9       7
123458888233871  XYZWRT493B9ABCDEDCF3C00266C568A2    8    9       7
123458888233883  XYZWRT869D5ABCDE41AD15F37E956720    8    9       7
123458888233907  POSUSF6AAC016TI2A8E05C4FE49FE92C    8    9       A
123458888233937  XYZWRT5AFEEABCDEA37E9A1135356C73    8    9       7
123458888233679  XYZWRTED849ABCDE03E0FD66CE356D7B    8    9       A
123458888233682  XYZWRT68107ABCDEEA08EB6325B566BE    8    9       7
123458888233730  XYZWRT02FE2ABCDE521CC167A3256DD1    8    9       7
123458888233732  XFSOIS0D8E3A3705699DC15D40D30AB9    8    9       A
123458888233762  XYZWRT2971CABCDEE257D00E3C856928    8    9       7
123458888233836  XYZWRTCBF82ABCDE7775DDAEFBD56394    8    9       7
123458888233871  XYZWRT493B9ABCDEDCF3C00266C568A2    8    9       7
123458888233883  XYZWRT869D5ABCDE41AD15F37E956720    8    9       7
123458888233907  POSUSF6AAC016TI2A8E05C4FE49FE92C    8    9       A
123458888233937  XYZWRT5AFEEABCDEA37E9A1135356C73    8    9       7
123458888233679  XYZWRTED849ABCDE03E0FD66CE356D7B    8    9       A
123458888233682  XYZWRT68107ABCDEEA08EB6325B566BE    8    9       7
123458888233730  XYZWRT02FE2ABCDE521CC167A3256DD1    8    9       7
123458888233732  XFSOIS0D8E3A3705699DC15D40D30AB9    8    9       A
123458888233762  XYZWRT2971CABCDEE257D00E3C856928    8    9       7
123458888233836  XYZWRTCBF82ABCDE7775DDAEFBD56394    8    9       7
123458888233871  XYZWRT493B9ABCDEDCF3C00266C568A2    8    9       7
123458888233883  XYZWRT869D5ABCDE41AD15F37E956720    8    9       7
123458888233907  POSUSF6AAC016TI2A8E05C4FE49FE92C    8    9       A
123458888233937  XYZWRT5AFEEABCDEA37E9A1135356C73    8    9       7
123458888233679  XYZWRTED849ABCDE03E0FD66CE356D7B    8    9       A
123458888233682  XYZWRT68107ABCDEEA08EB6325B566BE    8    9       7
123458888233730  XYZWRT02FE2ABCDE521CC167A3256DD1    8    9       7
123458888233732  XFSOIS0D8E3A3705699DC15D40D30AB9    8    9       A
123458888233762  XYZWRT2971CABCDEE257D00E3C856928    8    9       7
123458888233836  XYZWRTCBF82ABCDE7775DDAEFBD56394    8    9       7
123458888233871  XYZWRT493B9ABCDEDCF3C00266C568A2    8    9       7
123458888233883  XYZWRT869D5ABCDE41AD15F37E956720    8    9       7
123458888233907  POSUSF6AAC016TI2A8E05C4FE49FE92C    8    9       A
123458888233937  XYZWRT5AFEEABCDEA37E9A1135356C73    8    9       7
123458888233679  XYZWRTED849ABCDE03E0FD66CE356D7B    8    9       A
123458888233682  XYZWRT68107ABCDEEA08EB6325B566BE    8    9       7
123458888233730  XYZWRT02FE2ABCDE521CC167A3256DD1    8    9       7
123458888233732  XFSOIS0D8E3A3705699DC15D40D30AB9    8    9       A
123458888233762  XYZWRT2971CABCDEE257D00E3C856928    8    9       7
123458888233836  XYZWRTCBF82ABCDE7775DDAEFBD56394    8    9       7
123458888233871  XYZWRT493B9ABCDEDCF3C00266C568A2    8    9       7
123458888233883  XYZWRT869D5ABCDE41AD15F37E956720    8    9       7
123458888233907  POSUSF6AAC016TI2A8E05C4FE49FE92C    8    9       A
123458888233937  XYZWRT5AFEEABCDEA37E9A1135356C73    8    9       7
123458888233679  XYZWRTED849ABCDE03E0FD66CE356D7B    8    9       A
123458888233682  XYZWRT68107ABCDEEA08EB6325B566BE    8    9       7
123458888233730  XYZWRT02FE2ABCDE521CC167A3256DD1    8    9       7
123458888233732  XFSOIS0D8E3A3705699DC15D40D30AB9    8    9       A
123458888233762  XYZWRT2971CABCDEE257D00E3C856928    8    9       7
123458888233836  XYZWRTCBF82ABCDE7775DDAEFBD56394    8    9       7
123458888233871  XYZWRT493B9ABCDEDCF3C00266C568A2    8    9       7
123458888233883  XYZWRT869D5ABCDE41AD15F37E956720    8    9       7
123458888233907  POSUSF6AAC016TI2A8E05C4FE49FE92C    8    9       A
123458888233937  XYZWRT5AFEEABCDEA37E9A1135356C73    8    9       7
AMIGA:barrywalker~> _

# 6  
Old 09-17-2014
Hello wisecracker,

Thank you, your code produces correct output!

Best regards
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Break one long string into multiple fixed length lines

This is actually a KSH under Unix System Services (Z/OS), but hoping I can get a standard AIX/KSH solution to work... I have a very large, single line file in Windows, that we download via FTP, with the "SITE WRAP" option, into a Z/OS file with an LRECL of 200. This essentially breaks the single... (4 Replies)
Discussion started by: bubbawuzhere
4 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

Enumerate lines until each line break using awk

Hi, I have the following data: This this DT 0.99955 0 4 is be VBZ 1 5 7 sentence sentence NN 0.916667 8 16 one one NN 0.545078 17 20 . . Fp 1 20 21 This this DT 0.99955 22 26 is be VBZ 1 27 29 the the DT 1 30 33 second 2 JJ 0.930556 34 40 sentence sentence NN 0.916667 41 49... (1 Reply)
Discussion started by: owwow14
1 Replies

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

5. Shell Programming and Scripting

Trying to break up a lines in a variable

I was trying to figure out a way to split along a CR in a variable. In the code below, the result for CPU returns CPU=`cat /proc/cpuinfo | grep -i 'model name' |awk -F ':' '{ print $2}'` for echo $CPU AMD Phenom(tm) 9850 Quad-Core Processor AMD Phenom(tm) 9850 Quad-Core Processor... (7 Replies)
Discussion started by: baggins2000
7 Replies

6. Shell Programming and Scripting

break: cannot break

hi guys I am working on a menu for linux... some basic stuff. but I have an issue. I got 1 server where something is working and the same thing does not work in the same way in another linux box Basically I am simulating a command line where user insert some commands and to end and go back... (7 Replies)
Discussion started by: karlochacon
7 Replies

7. Shell Programming and Scripting

Awk to Break lines to multiple lines.

Input File: nawk -F "|" '{ for(i=1;i<=NF;i++) { if (i == 2) {gsub(",","#",$i);z=split($i,a,"")} else if (i == 3) {gsub(",","#",$i);z=split($i,b,"")} } if(z > 0) for(i=1;i<=z;i++) print $1,a,"Test"; if(w > 0) for(j=1;j<=w;j++) ... (1 Reply)
Discussion started by: pinnacle
1 Replies

8. Shell Programming and Scripting

Break lines up into single lines after each space in every line

It sounds a bit confusing but what I have is a text file like the example below (without the Line1, Line2, Line3 etc. of course) and I want to move every group of characters into a new line after each space. Example of text file; line1 .digg-widget-theme2 ul { background: rgb(0, 0, 0) none... (7 Replies)
Discussion started by: lewk
7 Replies

9. Shell Programming and Scripting

join lines on line break in files

i had a file where lines appear to be broken when they shouldn't eg Line 1. kerl abc sdskd sdsjkdlsd sdsdksd \ Line 2. ksdkks sdnjs djsdjsd i can do a shift join to combine the lines but i there are plenty of files with this issue Line 1. kerl abc sdskd sdsjkdlsd sdsdksd ksdkks sdnjs... (6 Replies)
Discussion started by: mad_man12
6 Replies

10. Shell Programming and Scripting

Break one line to many lines using awk

Break one line to many lines using awk The below code works but i want to implement without combining field 2 and 3 and then splitting i would like to do this in one command instead of writing multiple commands and creating multiple lines. nawk -F"|" '{print $1,$2SUBSEP$3}' OFS="|" file >... (16 Replies)
Discussion started by: pinnacle
16 Replies
Login or Register to Ask a Question