Is there a way to adjust spacing of a line using k shell?
e.g I have a file below
$ cat file1
AAA BBB CCC
A B C
AAAA BB CC
I want each word to be adjusted with spaces to have 10 character length like below:
AAA BBB CCC
A B C
AAAA BB CC
Any help will be appreciated.
Steve
anbu23
2
awk ' { for(i=1;i<=NF;++i) printf("%-10s",$i); printf("\n"); } ' file
anbu's awk solution is better, as it will work for any number of fields, but if you want to use shell builtins only...
$ while read line; do
> set -- ${line}
> printf "%-10s%-10s%-10s\n" $1 $2 $3
> done < spacetest.txt
AAA BBB CCC
A B C
AAAA BB CC
Cheers
ZB
while read;do printf "%-10s" $REPLY; printf "\n"; done<inputfile
or (for fixed numer of fields):
printf "%-10s%-10s%-10s\n" $(<inputfile)