So for the start, we have a file with the following lines, called datafile.txt
1 some test lines here
but not all lines contain nubers
3 and here is the last one
and we have one bash variable $ADDED
with the line content what want add
ADDED="==This is the new line=="
So, add line after the first line
ADDED="==This is the new line=="
< datafile.txt sed "1a \
$ADDED
"
the result:
1 some test lines here
==This is the new line==
but not all lines contain nubers
3 and here is the last line
Add line after all lines what are starts with a number
< datafile.txt sed "/^[0-9]/a \
$ADDED
"
the result:
1 some test lines here
==This is the new line==
but not all lines contain nubers
3 and here is the last line
==This is the new line==
Add line to the start, so insert before first line
< datafile.txt sed "1i \
$ADDED
"
result
==This is the new line==
1 some test lines here
but not all lines contain nubers
3 and here is the last line
You can "substitute" the end of the line for adding a new one
< datafile.txt sed "/all/s/$/\
$ADDED/"
the above example add line after the line what contains word "all" by substitution
1 some test lines here
but not all lines contain nubers
==This is the new line==
3 and here is the last line
You can even split line and add between
< datafile.txt sed "/all/s/(.*lines )(.*)/1\
$ADDED\
2/"
the above will search for the line what contains the word "all" and split it after the word "lines". The result:
1 some test lines here
but not all lines
==This is the new line==
contain nubers
3 and here is the last line
Last thing. It is impossible to parsing HTML with regural expressions, check the link in sputnik's comment.
BUT, that's not mean than it is impossible match some parts of HTML files. If you know what you want match (and not parse) - you can safely use regular expression for HTML too. Simply, many peoples here don't know the difference between parsing and matching.
So, if your html files has well known structure, e.g. you are sure than your html will the above structure all times, you can safely write:
<your_file.html sed "/^<tr><th>/a \
<tr><td>new Row:1 Cell:1</td><td>Row:1 Cell:2</td><td>Row:1 Cell:3</td><td>Row:1 Cell:4</td>
"
and you will get
<table id="tfhover" class="tftable" border="1">
<tr><th>HEADER1</th><th>HEADER2</th><th>HEADER3</th><th>HEADER4</th></tr>
<tr><td>new Row:1 Cell:1</td><td>Row:1 Cell:2</td><td>Row:1 Cell:3</td><td>Row:1 Cell:4</td>
<tr><td>Row:1 Cell:1</td><td>Row:1 Cell:2</td><td>Row:1 Cell:3</td><td>Row:1 Cell:4</td></tr>
</table>
simply because we NOT PARSING the html code, we are only MATCHING some line patterns..