I have a bash script which reads lines from a text file with 4 columns(no headers). The number of lines can be a maximum of 4 lines or less. The words in each line are separated by SPACE character.
[email protected] [email protected];[email protected] Sub1 MailBody1
[email protected] [email protected];[email protected] Sub2 MailBody2
[email protected] [email protected];[email protected] Sub3 MailBody3
[email protected] [email protected];[email protected] Sub4 MailBody4
Currently, I am parsing the file and after getting each line, I am storing each word in every line into a variable and calling mailx four times. Wondering if is there is an elegant awk/sed solution to the below mentioned logic.
- find total number of lines
- while
read $line
, store each line in a variable - parse each line as
i=( $line1 )
,j=( $line2 )
etc - get values from each line as
${i[0]}
,${i[1]}
,${i[2]}
and${i[3]}
etc - call
mailx -s ${i[2]} -t ${i[1]} -r ${i[0]} < ${i[3]}
- parse next line and call
mailx
- do this until no more lines or max 4 lines have been reached
Do awk or sed provide an elegant solution to the above iterating/looping logic?