matgold
asked on
How can I extract job_name and host_name from a text file?
I have a text file that contain info about each job. I need to extract job_name and host_name.
The format is as follow. as you can see, each job is seperated by /* ----------------- JOB_NAME ----------------- */
I need to extract "JOB_NAME" and host: yahoo
the output should be like so.
JOB_NAME, host: yahoo
JOB_NAME, host: yahoo
JOB_NAME, host: yahoo
JOB_NAME, host: yahoo
/* ----------------- JOB_NAME ----------------- */
blah
blah
host: yahoo
blah
blah
/* ----------------- JOB_NAME ----------------- */
blah
blah
host: yahoo
blah
blah
The format is as follow. as you can see, each job is seperated by /* ----------------- JOB_NAME ----------------- */
I need to extract "JOB_NAME" and host: yahoo
the output should be like so.
JOB_NAME, host: yahoo
JOB_NAME, host: yahoo
JOB_NAME, host: yahoo
JOB_NAME, host: yahoo
/* ----------------- JOB_NAME ----------------- */
blah
blah
host: yahoo
blah
blah
/* ----------------- JOB_NAME ----------------- */
blah
blah
host: yahoo
blah
blah
ASKER
are you sure about the matching, I'm not getting anything
ASKER
Adam,
Can we do this instead. I'm going to extract the first five characters.
if it equal "host:" then 1 to rec-cnt.
but I need to be able to add up a total for each type of machine.
How can I do that.
Can we do this instead. I'm going to extract the first five characters.
if it equal "host:" then 1 to rec-cnt.
but I need to be able to add up a total for each type of machine.
How can I do that.
When I run the posted script on the data you gave, i get this exact output:
JOB_NAME, host: yahoo
JOB_NAME, host: yahoo
If your real data looks different, post your real data (if necessary, replace confidential data with similar data - numbers with numbers, letters with letters...).
To check if the first five characters are "host:", you could do /^host:/. Add i at the end to ignore case /^host:/i.
>>if it equal "host:" then 1 to rec-cnt.
>>but I need to be able to add up a total for each type of machine.
Not sure what you mean by this. Where do you get the type of machine?
JOB_NAME, host: yahoo
JOB_NAME, host: yahoo
If your real data looks different, post your real data (if necessary, replace confidential data with similar data - numbers with numbers, letters with letters...).
To check if the first five characters are "host:", you could do /^host:/. Add i at the end to ignore case /^host:/i.
>>if it equal "host:" then 1 to rec-cnt.
>>but I need to be able to add up a total for each type of machine.
Not sure what you mean by this. Where do you get the type of machine?
ASKER
I'm sorry, I meant host not machine.
its not always going to be yahoo, it could be anything.
since I don't know what's out there, is there a way total up for each type of host.
its not always going to be yahoo, it could be anything.
since I don't know what's out there, is there a way total up for each type of host.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
perfect!
Thank You very much
Thank You very much
ASKER
currently it is sorting by total count, how can I sort by host name.
Change line 9 to:
foreach (sort keys %hosts) {
foreach (sort keys %hosts) {
ASKER
fantastic, thanks again
script.pl your_text_file.txt
Open in new window