2

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)" -))
do
    printf " -d "
    printf "$LOGIN" | xmllint --xpath "string(/form/input[$i]/@name)" -
    printf "="
    printf "$LOGIN" | xmllint --xpath "string(/form/input[$i]/@value)" -
done

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

user218669
  • 21
  • 3
  • Surely not with [regular expressions](http://stackoverflow.com/a/1732454). – 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

1 Answers1

0

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

LOGIN=...
printf "$LOGIN" | 
    perl -nE 'say "-d $1=$2" if /name="(.*?)".*?value="(.*)"/'
JJoao
  • 11,887
  • 1
  • 22
  • 44