POSIX shell compliant method to find matching line with HTML element by name, then extract HTML element value
Input Data Source
<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset='utf-8'>
</head>
<body>
<main>
<div class='wrapper'>
<div class='float1'>
<form id="form1" action="/endpoint" method="post">
<input name="input1" type="hidden" value="value1" />
<fieldset>
<input id="input2" name="input2" value="value2">
<input id="input3" name="input3" value="value3">
</fieldset>
</form>
</div>
</div>
</main>
<footer>
</footer>
</body>
</html>
Output required
value1
value2
value3
Logic required
- Find input element with name equal to "input1"
- For this element, extract value contents
Preferences
- SED or AWK would be preferred answer. Unsure of any other POSIX compliant method which could parse HTML.
- Command would should be reusable, so multiple Shell variables can use the same command (with a different element name)