Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

20 char lines from long string

Status
Not open for further replies.

apache7

Programmer
Aug 28, 2002
4
US
Gurus,

Being new to AWK, is there a way to take a very long string (over 2048) and create 20 character lines from it? I have a sample string that look like this:

ZP~19206-3*PAS~G~~~~LYC.RRAAE LXXPCLEAR,MODE*PO1~71~30~R EA~9.45~PE~BP~TK21280Y~VP~2328RY*PWW~V~~~~LDWLIXXT*PQA~8~150~RR~(.09~PE~BP~DK23252Y3~SS~21877Y3*

and would like to create something like this:

ZP~19206-3*PAS~G~~~~
~LYC.RRAAE LXXPCLEAR
,MODE*PO1~71~30~R EA
~9.45~PE~BP~TK21280Y
etc...

This string is read in from a file that has no control characters.

Thanks,

Henry
 
man fold

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Or a quick awk version:
Code:
function printCnt(line,cnt, xx) {
xx=1
  do {
        for (xx=1 ; xx <= cnt ; xx++) {
            printf(&quot;%c&quot;,substr(line,xx,1))
        }
        line = substr(line,xx,(length(line) - xx))
        #printf(&quot; Line length %d\n&quot;, length(line))
        printf &quot;\n&quot;
     } while (length(line) > 0) 
}


{

        printCnt($0,20)
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top