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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

80 Chr's per line 1

Status
Not open for further replies.

chomps302

MIS
Mar 9, 2005
1
US
I have a file with many data lines, any line can have any number of char.

I need to concatenate lines so that every line is EXACTLY 80 chars long and then put a ^M at the end of each line.

ie:

Have:

Chars.
1 2 3 4 5
12345678901234567890123456789012345678901234567890123456789
6 7 8
012345678901234567890

1111 22222 3333333 44444444 555555 666666
444 444 4444 444 4444 4444 44444 4444 44444 4444 444
5555 5555 555555 55555 55555 55555 55
6666666 6666666 666666666 6666666 66666666 66 6666666 66666



Need:

1111 22222 3333333 44444444 555555 666666 444 444 4444 444 4444 4444 44444 4444<---- This is 80th chr.
44444 4444 4445555 5555 555555 55555 55555 55555 556666666 6666666 666666666 66<---- This is 80th chr.
66666 66666666 66 6666666 66666

Thanks
Brandt
PMP






 
And what have you tried so far ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Hi:

Here's one way to do it:

#!/bin/ksh

while read line
do
printf "%-80.80s^M\n" "$line"
done < data.file > new.file

Be aware that the control-m is embedded. This means within vi in edit mode, press control-v and then control-m.

Regards,
 
Apparently the 80 character length includes the linefeed character?
Code:
BEGIN { max = 80 }
{ line = line $0
  if (length(line)>=max-1)
  { print substr(line,1,max-1)
    line = substr(line,max)
  }
}
END { if (length(line)) print line }
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top