tags:

views:

21

answers:

1

hi all

from my ksh script

.

echo $IP1  $ALIAS1 >> /etc/hosts
echo $IP2  $ALAIS2 >> /etc/hosts
echo $IP3  $ALIAS3 >> /etc/hosts

I get the hosts file as the following

10.10.10.10 node1_star
10.10.10.100    node_from_some_where
10.10.1.1              Node_HP_MACHINE

what the simple way to create the following hosts file view in order to get constant spaces between the IP to the aliases name as the follwoing:

(it could be by printf or by echo manipulation)

10.10.10.10        node1_star
10.10.10.100       node_from_some_where
10.10.1.1          Node_HP_MACHINE
+1  A: 

printf is a powerful function that can do exactely what you want.

printf "%-20s %s\n" "$IP1" "$ALIAS1" >> /etc/hosts
Lekensteyn

related questions