Hello experts.
I trying to achieve 2 things here. I'm trying to convert all of the host names to lower case and add an "m" to each hostname. Can anyone provide some guidance on what I can do? Your input is greatly valued!
Here are the desired results:
- read the host name from a file.
- convert from upper to lower case. ex SERVER > server
- add character "m" to the host name. ex. serverm
- write the desired output to a separate file called hosts.
---------- Post updated at 10:25 AM ---------- Previous update was at 10:23 AM ----------
# get the filename
#!/usr/bin/ksh
echo -n "Enter filename:"
read filename
# make sure the file exists for reading
if [ ! -f $filename ]; then
echo "filename $filename does not exists"
fi
# convert upper to lower case and write to hosts file
tr '[A-Z]' '[a-z]' <$filename > hosts
# add character m to the end of each hostname
if [[ $filename = "hosts" ]]; then
sed 's/./&m/6' hosts
exit 1
fi