Friday, August 15, 2014

One liner to parse parenthesized statements

msgbox: 
//messagebox("ñ",string(asc("ñ")))
//messagebox("Ñ",string(asc("Ñ")))
//messagebox("ñ",string(char(241)))

messagebox("Hi")

IF Trim(sle_user_id.text) = "" AND Trim(sle_password.text) = "" THEN
    MessageBox(Titulo_Msg,&
              "Sr Usuario :~r~nDebe ingresar los datos solicitados.",StopSign!,Ok!)
    sle_user_id.SetFocus()
    Return
End If

IFS=$(echo -en "\n\b") && for a in $(grep '[Mm]essage[Bb]ox' msgbox); do echo $a$((($(echo "$a" | grep -o '[()]' | wc -w)%2)) && sed -n "/$a/{n;p;}" msgbox) | perl -lne '{@mystr=$_=~m/\((?>[^()]|(?R))*\)/g; print "@mystr\n" if $_ =~ m/\((?>[^()]|(?R))*\)/g; }' | sed 's/^(\(.*\))$/\1/g';done && unset IFS

Output is:
"ñ",string(asc("ñ"))
"Ñ",string(asc("Ñ"))
"ñ",string(char(241))
"Hi"
Titulo_Msg,& "Sr Usuario :~r~nDebe ingresar los datos solicitados.",StopSign!,Ok!

sed -n '/x(/,/)$/{s/.*x(//;s/)$//p}' msgbox_file.txt

Output: 
"ñ",string(asc("ñ"))
"Ñ",string(asc("Ñ"))
"ñ",string(char(241))

"Hi"
Titulo_Msg,&
   "Sr Usuario :~r~nDebe ingresar los datos solicitados.",StopSign!,Ok! 

No comments:

Post a Comment