I need to read data from a source and have to form a XML file using shell script. But first of all i don't know how to write multiple lines in a file using shell script
Use output redirection
echo '<fruit>' > foo.xml # overwrites echo ' <apple />' >> foo.xml # appends echo '</fruit> >> foo.xml # appends
Or use a "here document"
cat <<EndXML > foo.xml <fruit> <apple /> </fruit> EndXML
Better yet is to use a scripting/programming language that has support for XML. I like Perl and XML::LibXML but you may prefer something else.
The following creates a file named "file.txt" (or replaces the contents of the file if it already exists), and writes "foo" (without quotes) into it :
echo "foo" > file.txt
What you seem to look for is the following, appending the string "foo" (again, without quotes) in the file (and again, creating the file if it doesn't exist)
echo "foo" >> file.txt
So the following code will write three lines to "file.txt":
echo "foo" >> file.txt ; echo "bar" >> file.txt; echo "beer" >> file.txt