Break one long string into multiple fixed length lines


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Break one long string into multiple fixed length lines
# 1  
Old 08-04-2015
Code 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 long line down into multiple 200 byte records.

We are converting from FTP, to (OPENSSH) SFTP, which unfortunately does not include the "SITE WRAP" ability. Therefore, I'm attempting to come up with another means of accomplishing the task.

I have downloaded the file to USS, and have written a simple script to read in the record and split it out into multiple, 200 byte records, and write those out to a new file...

Code:
#!/bin/ksh                             
echo 'Starting break..'                
rm -f /homesh/ljamoo/SEQMAST2          
CPOS=1                                 
echo 'Loop..'                          
while read TLINE                       
 do                                    
 NLINE=`expr substr $TLINE $CPOS 200`  
 echo $NLINE >> /homesh/ljamoo/SEQMAST2
 CPOS=`expr $CPOS + 200`               
 done </homesh/ljamoo/SEQMAST          
echo 'Done.'                           
exit

However, this is not working as USS is apparently unable to read in the entire record into the TLINE variable...

Code:
Starting break..                                                                
Loop..                                                                          
read: /homesh/ljamoo/scripts/break.sh 6: FSUM9225 no memory: EDC5132I Not enough memory.
/homesh/ljamoo/scripts/break.sh 11: FSUM9225 no memory: EDC5132I Not enough memory.
/homesh/ljamoo/scripts/break.sh 11: FSUM9225 no memory: EDC5132I Not enough memory.
/homesh/ljamoo/scripts/break.sh 11: FSUM9225 no memory: EDC5132I Not enough memory.
....

So, does anyone have any suggestions on how else to break it down? Being a mainframe dinosaur, I have yet to wrap my head around the "sed" and "awk" commands, but hoping maybe there is something like that, which would accomplish this.

Thanks!
# 2  
Old 08-04-2015
This User Gave Thanks to vgersh99 For This Post:
# 3  
Old 08-04-2015
Since 'fold' also depends upon standard input, doesn't that limit the line length to the system default max line length.
An alternative solution would be to write a cobol program using GNUcobol, making the input file sequential with fixed record length (ie no record separator), and the output file line sequential.
# 4  
Old 08-04-2015
Worked like a charm! Thanks!
# 5  
Old 08-04-2015
If I correctly understand what you're trying to do (and since you aren't quoting the expansion of $NLINE in your echo statement, I'm not sure that I do), you might find that using dd is a lot easier than writing a COBOL program:
Code:
dd if=/homesh/ljamoo/SEQMAST of=/homesh/ljamoo/SEQMAST2 bs=200 conv=unblock

This will strip off trailing space characters from your input file (like your echo does), but it won't strip leading whitespace and won't convert sequences of spaces and tabs in the middle of your input lines to a single space (like your echo does).
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Convert variable length record to fixed length

Hi Team, I have an issue to split the file which is having special chracter(German Char) using awk command. I have a different length records in a file. I am separating the files based on the length using awk command. The command is working fine if the record is not having any... (7 Replies)
Discussion started by: Anthuvan
7 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

Deleting lines in a fixed length file where there is a word at specific location

I have a big file having 100 K lines. I have to read each line and see at 356 character position whethere there is a word "W" in it. If it is their then don't delete the line otherwise delete it. There are two lines as one Header and one trailer which should remain same. Can somebody... (5 Replies)
Discussion started by: mohit kanoongo
5 Replies

4. Shell Programming and Scripting

Split a fixed length file bases on last occurence of string

Hi, I need to split a file based on last occurece of a string. PFB the explanation I have a file in following format aaaaaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbbbbbb ccccccccccccccccccccccccccc ddddddddddddddddddddddddddd 3186rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr... (4 Replies)
Discussion started by: Neelkanth
4 Replies

5. Shell Programming and Scripting

Concatenating fixed length lines in shell script

I have a peculiar file with record format like given below. Each line is wrapped to next lines after certain number of characters. I want to concatenate all wrapped lines into 1. Input:(wrapped after 10 columns) This is li ne1 This is li ne2 and this line is too lo ng Shortline ... (8 Replies)
Discussion started by: kmanyam
8 Replies

6. Shell Programming and Scripting

Finding multiple column values and match in a fixed length file

Hi, I have a fixed length file where I need to verify the values of 3 different fields, where each field will have a different value. How can I do that in a single step. (6 Replies)
Discussion started by: naveen_sangam
6 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. UNIX for Dummies Questions & Answers

What the command to find out the record length of a fixed length file?

I want to find out the record length of a fixed length file? I forgot the command. Any body know? (9 Replies)
Discussion started by: tranq01
9 Replies

9. Shell Programming and Scripting

How to print string on screen according the fixed length?

Problem: entry_name="joke:hello:yellow:blue:default" print("%d %-12s\t%-10s\t%-5s\n", $i, $entry_name....); I just want to print the output like this index entry value .... 1 joke:hello:y 0 123 567 ellow:blue:d ... (1 Reply)
Discussion started by: a2156z
1 Replies

10. Shell Programming and Scripting

creating a fixed length output from a variable length input

Is there a command that sets a variable length? I have a input of a variable length field but my output for that field needs to be set to 32 char. Is there such a command? I am on a sun box running ksh Thanks (2 Replies)
Discussion started by: r1500
2 Replies
Login or Register to Ask a Question