I developed code down below, I would like improve this code for future needs. So I am thinking that if I use functions, the code could be much better than now it is and It will look organized.
So how I turned to a program or organized code block?
Could you please help me?
Version: Red Hat Enterprise Linux Server release 7.3 (Maipo)
(output must be same)
#!/bin/bash
hammer host list >| host.list
cat host.list | grep "RHEL Server" | awk -F'|' '{ print $3}' | sort >
host.modified1
grp=`sort host.modified1 | uniq -c`
echo "Linux Versions Grouped by Count" > host.modified1
echo "" >> host.modified1
echo "$grp" >> host.modified1
echo "" >> host.modified1
echo "Linux Versions and Hostnames" >> host.modified1
echo "" >> host.modified1
cat host.list | grep "RHEL Server" | awk -F'|' '{ print $3"|"$2 }' | sort
>> host.modified1
output;
Linux Versions Grouped by Count
8 RHEL Server 6.5
21 RHEL Server 6.6
1 RHEL Server 6.7
10 RHEL Server 6.8
39 RHEL Server 6.9
19 RHEL Server 7.2
34 RHEL Server 7.3
30 RHEL Server 7.4
Linux Versions and Hostnames
RHEL Server 6.5 | xxx.dnsname