I have xml file (say input.xml) of the following schema:<?xml version=1.0?>  <TagA>    <TagB>      <File Folder=FOLDER1M\1 File=R1.txt />    </TagB>    <TagB>      <File Folder=FOLDER1M\2 File=R2.txt />    </TagB>    <TagB>      <File Folder=FOLDER2M\1 File=R3.txt />    </TagB>  </TagA>I need to parse this file and write the output to another file. The required output should be of the following form:www.xyz.com\FOLDER1M\1\R1.txtwww.xyz.com\FOLDER1M\2\R2.txtwww.xyz.com\FOLDER2M\1\R3.txtWhat I have got so far is:echo 'cat /TagA/TagB/File/@*[name()=Folder or name()=File]' | xmllint --shell input.xml | grep '=' > xml_parsedThis gives me o/p of the form:/ > cat /TagA/TagB/File/@*[name()=Folder or name()=File]Folder=FOLDER1M\1File=R1.txtFolder=FOLDER1M\2File=R2.txtFolder=FOLDER2M\3File=R3.txtHow should I go about getting my required output instead of this current o/p?
XML parsing using xmllint and customizing the output
shell;shell script;xml;xmllint
Here's one way to do it. I just put your output into a file called sample.txt to make it easier to test, you can just append my commands to the end of your echo command:sample.txtFolder=FOLDER1M\1File=R1.txtFolder=FOLDER1M\2File=R2.txtFolder=FOLDER2M\3File=R3.txtcommand% cat sample.txt | sed 'h;s/.*//;G;N;s/\n//g' | sed 's/Folder=\|//g' | sed 's/File=/\\/' | sed 's/^/www.xyz.com\\/'Breakdown of the commandjoin every 2 lines together# sed 'h;s/.*//;G;N;s/\n//g'Folder=FOLDER1M\1File=R1.txtFolder=FOLDER1M\2File=R2.txtFolder=FOLDER2M\3File=R3.txtstrip out Folder= & # sed 's/Folder=\|//g'FOLDER1M\1File=R1.txtFOLDER1M\2File=R2.txtFOLDER2M\3File=R3.txtReplace File= with a '\'# sed 's/File=/\\/'FOLDER1M\1\R1.txtFOLDER1M\2\R2.txtFOLDER2M\3\R3.txtinsert www.xyz.com# sed 's/^/www.xyz.com\\/'www.xyz.com\FOLDER1M\1\R1.txtwww.xyz.com\FOLDER1M\2\R2.txtwww.xyz.com\FOLDER2M\3\R3.txtEDIT #1The OP updated his question asking how to modify my answer to delete the first line of output, for example:/ > cat /TagA/TagB/File/@*[name()=Folder or name()=File]......I mentioned to him that you can use grep -v ... to filter out lines that aren't relevant like so:% cat sample.txt | grep -v / > | sed 'h;s/.*//;G;N;s/\n//g' | sed 's/Folder=\|//g' | sed 's/File=/\\/' | sed 's/^/www.xyz.com\\/'Additionally to write the entire bit out to a file, that can be done like so:% cat sample.txt | grep -v / > | sed 'h;s/.*//;G;N;s/\n//g' | sed 's/Folder=\|//g' | sed 's/File=/\\/' | sed 's/^/www.xyz.com\\/' > /path/to/some/file.txt