Server1 is just i put it randomly, Actually name of the server will be like cetiss, nik.tikkr etc. and name will be differnt. So if file name contains citiss it will be into /home/username/temp/hosts/citiss
so the filename format is the same as what you mentioned? Please specify your req correctly otherwise we would end up doing guess work and you will never get the desired answer
if server name is at field 2 (underscroe _ seperated)
for file in * ; do
dir_name=`echo $file | awk -F_ '{print $2}'`
# Create directories here if they are not there already
mv $file /home/username/temp/hosts/${dir_name}
done
for file in * ; do
dir_name=`echo $file | awk -F_ '{print $3}'`
# Create directories here if they are not there already
mv $file /home/username/temp/hosts/${dir_name}
done