I want to write a script to be executed in the terminal.
I’m editing xml files and I want to add a string or strings after the head of the xml column is detected..
Here is a sample xml
bunch of line
more unimportant lines
and they can very in number
<States>
<item1> something something </item1>
<item2> something something </item1>
<item3> something something </item1>
</states>
Now I want to add an item 4. However, I want it to be inserted before item1.
Idealy, the file would when look like:
bunch of line
more unimportant lines
and they can very in number
and even some lines were added here
and here
and here
<States>
<item4> something something </item1>
<item1> something something </item1>
<item2> something something </item1>
<item3> something something </item1>
</states>
Note that there was other stuff added to the top that is irrelevent to the code. These are comments that are going to be going in.
I am open to doing this in perl, but shell would be even better.
You can try this assuming your heading
Statesis fixedAfter this
your_file.tmpwill have inserted lines fromfile_to_insert.