I need help! I'm trying to write a bash script that asks the user two questions and takes the users answers and sends them and some other text to a particular line of a file that is in a different directory. Am I wrong in thinking that sed is the only way to add text to a particular line of a file?
The text that I want to add looks like this:
Code:
<track><path>$answer1</path><title>$answer2</title></track>
I want to add this line of text to line 3 of the xml file that is in a different directory.
The script looks something like this so far:
Code:
#!/bin/bash
read -p "Question 1? " $answer1;
read -p "Question 2? " $answer2;
# here's where the sed part will happen. I've tried the following
sed -i 3i"<track><path>'$answer1'</path><title>'$answer2'</title></track>" ../player/playlist.xml;
This isn't working. What am I doing wrong? Should I even be using sed for this? I have NO sed experience! I've been reading up on sed all day and I feel more confused and overwhelmed by it than I did when I knew literally nothing about it. Any help would be much appreciated! Thanks!