The above while loop works well as a simple alternative to sed and awk if you have a lot of control over the display of lines of text in a file. The read command can also use the specified delimiter using the -d flag.
Another simple example:
I used mysql to capture a list of users and hosts by placing it in the / tmp / userlist file with text as shown:
user1 host1 user2 host2 user3 host3
I passed these variables to the mysql command to get the information about the provision of data for these users and hosts and add to / tmp / grantlist:
cat /tmp/userlist | while read user hostname; do echo -e "\n\nGrabbing user $user for host $hostname..." mysql -u root -h "localhost" -e "SHOW GRANTS FOR '$user'@$hostname" >> /tmp/grantlist done
source share