9thTee
asked on
Need shell script to split line into variables
Hi,
I am needing a shell script that will help automate sending reports via email to our users. I have everything ready except for one part.
All of the reports that we print has the email address and report name on line 2 of the report. Like this:
mark@gmail.com IC Trial Balance Report
The email address can be different for each report and the report name different as well. There will be spaces to the left of the email address then some amount of spaces between the eamil address and the report name. It is centered on the line. The report is temporarily stored in a file named /var/tmp/report$$.rpt
What I need, is some code to put in a shell script that will look at line 2 of the report, find the email address and split it into one variable and the report name into another. That way I can send the email to the email address variable and use the report name as the subject.
Maybe awk or sed?
Thanks,
Mark
I am needing a shell script that will help automate sending reports via email to our users. I have everything ready except for one part.
All of the reports that we print has the email address and report name on line 2 of the report. Like this:
mark@gmail.com IC Trial Balance Report
The email address can be different for each report and the report name different as well. There will be spaces to the left of the email address then some amount of spaces between the eamil address and the report name. It is centered on the line. The report is temporarily stored in a file named /var/tmp/report$$.rpt
What I need, is some code to put in a shell script that will look at line 2 of the report, find the email address and split it into one variable and the report name into another. That way I can send the email to the email address variable and use the report name as the subject.
Maybe awk or sed?
Thanks,
Mark
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks James, that worked perfectly.
Mark
Mark
You're welcome. Glad I could help.
James
James
eaddr="`sed -n '2s/^ *\([^ ][^ ]*\).*/\1/p' /var/tmp/report$$.rpt`"
rname="`sed -n '2s/^ *[^ ][^ ]* *\(.*\) *$/\1/p' /var/tmp/report$$.rpt`"
James