I have a input file and an xml file.input file-/user/sht227_89,45_99/user/sht1230_90/user/sht2441_50The file has alternate lines containing path and position.xml file-<aaa><command name=move><domain><path></path><positions></positions></domain><domain><path></path><positions></positions></domain><domain><path></path><positions></positions></domain></command></aaa>I need to write a script to give the below output xml required and then run some commands using the below xml as input-<aaa><command name=move><domain><path>/user/sht</path><positions>227_89,45_99</positions></domain><domain><path>/user/sht1</path><positions>230_90</positions></domain><domain><path>/user/sht2</path><positions>441_50</positions></domain></command></aaa>I have tried extracting line by line from the input file and placing it in the xml, but the issue is that every occurrence of <path> is replaced by the first input line.Using GNU bash 4.1.2.
Reading data from an input file and placing the data in appropriate fields in an xml
text processing;awk;sed;xml
With a single GNU sed script you could do something likesed -n '/<aaa>/,/<.aaa>/!{H;d}G;:as_>\(</path>.*\n\)\n\([^\n]*\)_>\2\1_s_>\(</positions>.*\n\)\n\([^\n]*\)_>\2\1_;ta;P;s/.*\n\n/\n/;h' input.txt input.xmlThe first line collects all lines from the first file in the hold buffer.Then for each line of the second file the hold buffer is appended with G. If it's a path or positions the first segment of the hold buffer is moved insides the tags with one of the two s commands.In any case the line is printed (P) and removed (s/.*\n\n/\n/) and what's left of the replace list is moved back to the hold buffer for the next cycle (h).