-2

I have a HTML file with following code <input name="Patient_Id" type="text" id="Patient_Id" tabindex="10" class="forms" oncopy="return false" oncut="return false" onpaste="return false" autocomplete="off" style="font-family:Arial;">

Now I have to add a value in the end depending on what the tabindex value is

For example

I am expecting a output as <input name="Patient_Id" type="text" id="Patient_Id" tabindex="10" class="forms" oncopy="return false" oncut="return false" onpaste="return false" autocomplete="off" style="font-family:Arial;" value=tabindex10>

Similarly if the input is <input name="Patient_Name" type="text" id="Patient_Name" tabindex="11" class="forms" oncopy="return false" oncut="return false" onpaste="return false" autocomplete="off" style="font-family:Arial;">

I am looking for output as <input name="Patient_Name" type="text" id="Patient_Name" tabindex="11" class="forms" oncopy="return false" oncut="return false" onpaste="return false" autocomplete="off" style="font-family:Arial;" value=tabindex11>

Here my goal is to replace the input tag on place in the file using sed command and then render the html page

Hemant
  • 94
  • 6
  • [Do not parse html with regex](https://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags). – KamilCuk Mar 11 '21 at 13:47

1 Answers1

0

With the following input:

<input name="Patient_Id" type="text" id="Patient_Id" tabindex="10" class="forms" oncopy="return false" oncut="return false" onpaste="return false" autocomplete="off" style="font-family:Arial;">abc</input>

The following comand:

xmlstarlet ed -a '/input' --type attr -n value -v "tabindex$(xmlstarlet sel -t -v '/input/@tabindex' inputfile)" inputfile

outputs:

<?xml version="1.0"?>
<input name="Patient_Id" type="text" id="Patient_Id" tabindex="10" class="forms" oncopy="return false" oncut="return false" onpaste="return false" autocomplete="off" style="font-family:Arial;" value="tabindex10">abc</input>
KamilCuk
  • 120,984
  • 8
  • 59
  • 111