I need to update almost 100 HTML pages that contain 15-20 form fields each.
To pass Section 508 compliance, they all need to be uniquely named.
Each form-group has three of the same values for attributes like this:
<label for="input-title" class="control-label">Title*</label>
<input class="form-control" id="input-title" name="input-title" value="SA Analyst" required>
Notice the for, name and id attributes are all the same.
I just need it to be something like this with an incrementing number at the end:
<label for="input-title21" class="control-label">Title*</label>
<input class="form-control" id="input-title21" name="input-title21" value="SA Analyst" required>
The challenge is to: - loop through all form fields in an HTML file (see regex below) - update each "form-group" with an incrementing number appended to the end of each of the three attribute values "for, name and id" - make sure each form-group has the same appended, incremented number (i.e. every three attributes would get the same number in the current loop)
Here is the starting bash code I am working with:
#!/bin/bash
FILES=/Users/Administrator/files/*.html
counter=1
for f in $FILES
do
echo "Processing $f file..."
# take action on each file. $f store current file name
# cat $f
# sed 's/<input/<input2/g' $f > $f.txt
sed "s/<input/<input$counter/g" $f > $f.txt
echo $counter
((counter++))
done
echo All done
This code successfully updates the input with the counter variable number and saves it to a .txt file but this is not yet the solution since it updates ALL input fields in the HTML file with the same incremented number.
Here is the regex I came up with that finds the form groups that need to be changed:
(.*for\=")([0-9A-Za-z-]+)(".*\n\s*[0-9A-Za-z\<\>\-\=\"\s]*[id=|name=]")([0-9A-Za-z-]+)(".*[id=|name=]")([0-9A-Za-z-]+)("\s[type|req])
So how do I integrate this regex with the bash code above and update the three attributes in every form-group?