ararghat has asked for the wisdom of the Perl Monks concerning the following question:
I am trying to write a script for getting parameter & variable inside case block appended by nested case block. Can we write a subroutine for this using simple regular expressions. Nested case block is creating problem for me.
I was trying to match the content between "case" and "esac" ,but main case is counter with "esac" of nested case block.
A piece of the file is given below.
file.txt case `pattern` in ARAR) old_file="ak.csv" datefile="ak_nt_$curr_date.csv" case `kumar` in dbk*) newwack="rac_client_$curr_date.ack" IN_DIR="class/5060" ;; src) src_folder="class/5061" ;; *) echo "invalid parameter" ;; esac ;; SINGH) old_file="abh_cash.csv" date_file="ods_nt_cash_acc_$curr_date.csv" newwack="rac_cash_acc_$curr_date.ack" IN_DIR="xyx\5060" ;; GHAT) old_file="ods_ven.csv" newfile="ods_nt_ven_$curr_date.csv" newwack="rac_vendor_$curr_date.ack" IN_DIR="ofc\5060" case `para` in kol*) newreck="client_$curr_simul.ack" IN_DIR="vid/234" ;; src1*) src_folder="class/5061" ;; esac ;; esac
Output should be:
ARAR:old_file="ak.csv" ARAR:datefile="ak_nt_$curr_date.csv" ARAR:dbk*:newwack="rac_client_$curr_date.ack" ARAR:dbk*:IN_DIR="class/5060" ARAR:src:src_folder="class/5061" SINGH:old_file="abh_cash.csv" SINGH:date_file="ods_nt_cash_acc_$curr_date.csv" SINGH:newwack="rac_cash_acc_$curr_date.ack" SINGH:IN_DIR="xyx\5060" GHAT:old_file="ods_ven.csv" GHAT:newfile="ods_nt_ven_$curr_date.csv" GHAT:newwack="rac_vendor_$curr_date.ack" GHAT:IN_DIR="gunda\5060" GHAT:kol*:newreck="client_$curr_simul.ack" GHAT:kol*:IN_DIR="vid/234" GHAT:src1*:src_folder="class/5061"
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Getting content of case statement appended by inner case statement
by hippo (Archbishop) on Oct 12, 2016 at 11:31 UTC | |
|
Re: Getting content of case statement appended by inner case statement
by Corion (Patriarch) on Oct 12, 2016 at 11:45 UTC | |
|
Re: Getting content of case statement appended by inner case statement
by dsheroh (Monsignor) on Oct 12, 2016 at 11:38 UTC | |
by ararghat (Novice) on Oct 12, 2016 at 11:48 UTC |