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"

In reply to Getting content of case statement appended by inner case statement by ararghat

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.