captainK has asked for the wisdom of the Perl Monks concerning the following question:
Dear Monks,
i've been doing the following for years in KSH with something like the below but need to do it in Perl now. i have been trawling your site and the web for days now and am totally lost on how to do it in a perl.pl script.
Tried numerous while and foreach (<MYFILE>) examples and using split on ":" etc etc.. They all seem to either print the below every time for every line multiple times (like a cartesian join) of grabled mess. I have so many hacks that have failed i dont want to bother you with them. basically we need to do the following in PERL that we are currently doing in KSH.
Any assistance would be most greatly appreciated.
br&thnx, karl
Here's the KSH with for loop, cut, grep:
#!/bin/ksh for t in $(cat $MYFILE) do job_name=`echo $t | grep job_name | cut -d: -f2` days_of_week=`echo $t | grep days_of_week | cut -d: -f2` start_times=`echo $t | grep start_times | cut -d: -f2` printf "$job_name:$days_of_week:$start_times" done
----- Example (Target Output) ------
myservername001.dlog.xyz:su,mo,tu,we,th,fr,sa:"12:00" myservername001.osaudit.xyz:su,mo,tu,we,th,fr,sa:"12:00" myservername001.expdb.xyz:su,mo,tu,we,th,fr,sa:"12:00"
----- MYFILE (Source DATA) --------- /*----- myservername001.dblogs.xyz -----*/ job_name:myservername001.dlog.xyz days_of_week: su,mo,tu,we,th,fr,sa start_times: "12:00" /*----- myservername001.osaudit.xyz -----*/ job_name:myservername001.osaudit.xyz days_of_week: su,mo,tu,we,th,fr,sa start_times: "12:00" /*----- myservername001.expdb.xyz -----*/ job_name:myservername001.expdb.xyz days_of_week: su,mo,tu,we,th,fr,sa start_times: "12:00"
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: [KSH convert to PERL] Rollup multi line values to single row outputs.
by BrowserUk (Patriarch) on Jan 26, 2015 at 16:31 UTC | |
|
Re: [KSH convert to PERL] Rollup multi line values to single row outputs.
by GotToBTru (Prior) on Jan 26, 2015 at 16:46 UTC |