Currently I have a shell script like this:

LOGIN=`curl 'https://www.ponta.jp/u/LWAS900/SLWAS900010.htm' -sS | grep '<input type="hidden" name\|<form\|</form'`

for i in $(seq $(printf "$LOGIN" | xmllint --xpath "count(/form/input)" -))
    printf " -d "
    printf "$LOGIN" | xmllint --xpath "string(/form/input[$i]/@name)" -
    printf "="
    printf "$LOGIN" | xmllint --xpath "string(/form/input[$i]/@value)" -

I want to do the same thing on a unix environment which doesn't have xpath. Can anyone tell me how to do it?

  • Surely not with regular expressions. – TNW Jan 16 '16 at 17:29
  • is installing a library an option? I would be suggesting perl and XML::Twig as a starting point, because that ... is another way of doing xpath style searches on your input. – Sobrique Jan 22 '16 at 11:46

A XML parser based solution is the way to go. Nevertheless here goes a quick regular expression hack:

printf "$LOGIN" | 
    perl -nE 'say "-d $1=$2" if /name="(.*?)".*?value="(.*)"/'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.