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

Need to add characters to fill file for a set length 1

Status
Not open for further replies.

UCF87

Technical User
Feb 13, 2003
44
US
I have a file which is variable in file length. I need to add a Comma or something to fill each line for a set length of 79. Any one have an idea how to do this? Thanks in advance.

Example

01,071000505,071000505,030404,0736,434,,,2/
03,5800378290,USD,010,000,,,015,000,,,040,000,,,
03,2350547,USD,010,2500000,,,015,2500000,,,040,2500000,,,
03,2349656,USD,010,000,,,015,000,,,040,000,,,045,000,,,,

Would be

01,071000505,071000505,030404,0736,434,,,2/,,,,,,,,,,,,,,,,
03,5800378290,USD,010,000,,,015,000,,,040,000,,,,,,,,,,,,,,
03,2350547,USD,010,2500000,,,015,2500000,,,040,2500000,,,03
2349656,USD,010,000,,,015,000,,,040,000,,,045,000,,,,,,,,,,
 
Try this. Make a script containing the following...
Code:
#!/bin/ksh

typeset -L79 LINE79
COMMAS=',,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,'

while REC=$(line)
do
        LINE79=${REC}${COMMAS}
        print ${LINE79}
done < $1
Hope this helps.

 
Ok.. umm dumb question. I see the output correct on the screen but the file has not changed.
Where do I place the redirection for the output file?

Here is what I have:

typset -L79 LINE79
COMMAS=',,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
,,,,,,,'

while REC=$(line)
do
LINE79=${REC}${COMMAS}
print ${LINE79}

done < BANKRECON
 
Leave the script as I had it. Say you call the script [tt]commapad[/tt], you would then run it like this...
[tt]
commapad bankrecon.dat > bankrecon.new
[/tt]
That way the file name isn't hard coded and you can use this as a command on any file name.

Hope this helps.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top