Link to home
Start Free TrialLog in
Avatar of 9thTee
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
ASKER CERTIFIED SOLUTION
Avatar of James0628
James0628

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of James0628
James0628

Hmm.  I've tested the sed commands, but haven't actually tested using them like that to assign values to variables (not running Unix at the moment).  If the values don't come out right, try adding/changing quotes.  Something like:

eaddr="`sed -n '2s/^ *\([^ ][^ ]*\).*/\1/p' /var/tmp/report$$.rpt`"

rname="`sed -n '2s/^ *[^ ][^ ]*  *\(.*\) *$/\1/p' /var/tmp/report$$.rpt`"


 James
Avatar of 9thTee

ASKER

Thanks James, that worked perfectly.

Mark
You're welcome.  Glad I could help.

 James