![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| perl -write values in a file to @array in perl | meghana | Shell Programming and Scripting | 27 | 06-07-2009 05:05 PM |
| Problem In Formating Table as Output | Lo11001 | Shell Programming and Scripting | 1 | 05-12-2008 06:35 AM |
| Output formating | jaydeep_sadaria | Shell Programming and Scripting | 1 | 04-10-2008 12:39 PM |
| formating output | Krrishv | Shell Programming and Scripting | 20 | 02-02-2007 09:39 AM |
| Formating cal output | Krrishv | Shell Programming and Scripting | 2 | 01-11-2007 10:46 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
formating array file output using perl
Hello,
I am trying to output the values in an array to a file. The output needs to be formated such that each array value is left jusified in a field 8 character spaces long. Also, no more than 6 fields on a line. For example: @array= 1..14; Needs to be output to the file like so: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 Of course, the amount of array values will vary. Can't this be done with the printf function? Please Help, seismic_willy |
|
||||
|
Well, here's a while command that uses printf to output a unix array, and it closes out the line after every 6th entry:
Code:
#!/bin/ksh
a[1]=this
a[2]=array
a[3]=is
a[4]=holding
a[5]=nine
a[6]=entries
a[7]=right
a[8]=now
a[9]=.
i=1
w=0
while [ "${a[$i]}" ]
do
if [ $w -eq 6 ] ; then
printf "\n"
w=0
fi
printf "%-8s" ${a[$i]}
((i=i+1))
((w=w+1))
done
printf "\n"
exit 0
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|