Create one xml file from one list of names


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Create one xml file from one list of names
# 1  
Old 01-29-2017
Create one xml file from one list of names

Actually I have one list of channels names like:

Code:
Rai 1
Rai 1 +1HD
Rai 1 +2HD
Rai 2
Rai 2 +1HD
Rai 2 +2HD
.
.
.
.

From this list of names I need create one new xml file with this structure
Code:
 <channel id="Rai 1">
    <display-name lang="it">Rai 1</display-name>
    <icon src="http://www.my-website.com/logos/Rai_1.png" />
 </channel>
 <channel id="Rai 1 +1HD">
    <display-name lang="it">Rai 1 +1HD</display-name>
    <icon src="http://www.my-website.com/logos/Rai_1_+1HD.png" />
  </channel>
  <channel id="Rai 1 +2HD">
    <display-name lang="it">Rai 1 +2HD</display-name>
    <icon src="http://www.my-website.com/logos/Rai_1_+2HD.png" />
  </channel>
  <channel id="Rai 2">
    <display-name lang="it">Rai 2</display-name>
    <icon src="http://www.my-website.com/logos/Rai_2.png"/>
  </channel>
  <channel id="Rai 2 +1HD">
    <display-name lang="it">Rai 2 +1HD</display-name>
    <icon src="http://www.my-website.com/logos/Rai_2_+1HD.png"/>
  </channel>
  <channel id="Rai 2 +2HD">
    <display-name lang="it">Rai 2 +2HD</display-name>
    <icon src="http://www.my-website.com/logos/Rai_2_+2HD.png"/>
  </channel>
.
.
.
.

Is important the link http have one name without blank space.

I am trying to do it with xmlstarlet, but I am totally beginner about scripting and I can't find a solution. Smilie

Last edited by Tapiocapioca; 01-29-2017 at 03:33 PM..
# 2  
Old 01-29-2017
How about
Code:
awk '
        {print " <channel id=\"" $0 "\">"
         print "   <display-name lang=\"it\">" $0 "</display-name>"
         gsub (/ /, "_")
         print "   <icon src=\"http://www.my-website.com/logos/" $0 ".png\" />"
         print " </channel>"
        }
' file


Last edited by RudiC; 01-29-2017 at 04:19 PM.. Reason: removed two spaces from last print
This User Gave Thanks to RudiC For This Post:
# 3  
Old 01-29-2017
Another solution using bash shell:

Code:
#!/bin/bash

while read chan
do
    printf "<channel id=\"%s\">\n" "$chan"

    printf "    <display-name lang="it">%s</display-name>\n" "$chan"
    printf "    <icon src=\"http://www.my-website.com/logos/%s.png\" />\n"  \
        "${chan// /_}"
    printf "</channel>\n"
done < infile

This User Gave Thanks to Chubler_XL For This Post:
# 4  
Old 01-31-2017
Really thank you about both solutions, I need check the best one for me Smilie Smilie Anyway this is the only one forum where there is alsways someone ready to help!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Create a XML file for each row from the csv file

I have a CSV file that looks like this: File,Name,birthdate,Amount File1.xml,Name1,01.02.19,1000 File2.xml,Name2 01.02.20,1000 File3.xml,Name3,01.02.21,1000 I need it to turn it into an XML file for each row, My ultimate goal is for the File1.xml look like this: <?xml version="1.0"... (5 Replies)
Discussion started by: lxdorney
5 Replies

2. UNIX for Dummies Questions & Answers

List Directory names which have the file

Hi All, Can any one help me to list out the directory names which contain the specified file. See for example File name : file.201307014.LKT Have the directory structure as below. /app/work/data/INDIA/file.201307014.LKT /app/work/data/AMERICA/file.201307014.KTP... (5 Replies)
Discussion started by: Balasankar
5 Replies

3. UNIX for Dummies Questions & Answers

Need help how to create a file (xml) list all files from directory

I have more than 10K songs in two directories on a hard drive. I would like to create a file list all of files name then change to .xml extension to upload to iPhone so I have a Karaoke list on my iPhone. I need your help to create a file by using command in Linux. Files names: 0001 More... (4 Replies)
Discussion started by: ggcc
4 Replies

4. Shell Programming and Scripting

Create xml file using a content from another xml file

I need to create a xml file(master.xml) with contents from another xml files(children). I have below list of xml files in a temporary location (C:/temp/xmls) 1. child1.xml 2. child2.xml Below is the content of the child1.xml & child2.xml files, child1.xml <root> <emp> ... (3 Replies)
Discussion started by: vel4ever
3 Replies

5. Shell Programming and Scripting

get file names from the list

Hi Experts, Here is my scenario: Am maintaining a file which has list of logs with complete path and file names like bleow a/b/c/Daily/file1_20111012.log d/e/f/Monthly/file1_20111001.log g/h/Daily/file1_20110120.log i/Daily/file1_20110220.log How to copy the file names frm the list... (7 Replies)
Discussion started by: laxm
7 Replies

6. Shell Programming and Scripting

List of file names

I have the following list of file names stored in $fnames, so that if I do foreach f ($fnames) echo "$f" end I will get n02-z30-sr65-rgdt0p50-dc0p002-16x12drw-run1 n02-z30-sr65-rgdt0p50-dc0p002-16x12drw-run2 n02-z30-sr65-rgdt0p50-dc0p002-16x12drw-run3... (3 Replies)
Discussion started by: kristinu
3 Replies

7. Shell Programming and Scripting

How to create a xml file using Perl Script

Hi All, I have some data which needs to be saved in the xml file format.Can you guys please let me know how to do this using perl script. NOTE: the template of the xml file shall be depending on validation of the data done for some requirements. Basically to summarise, the fields in the xml... (5 Replies)
Discussion started by: girish.raos
5 Replies

8. UNIX for Advanced & Expert Users

extracting the component names from SVN changes xml file

Hi All, The following is the sample xml which is generated by a tool called HUDSON when ever change occurs in SVN(Sub version namespace). In the given XML , path/paths tags ll be vary depends on no.of changes. now , my requirement is, need a script which can extract the payment and... (1 Reply)
Discussion started by: geervani
1 Replies

9. Shell Programming and Scripting

read mp3 filename and create one XML for each file

Hi: I have a collection of mp3s and I need to create 1 xml file per mp3. I have: recording1.mp3 recording2.mp3 etc and I want to generate this kind of files. recording1.xml recording2.xml and inside each xml file I need to add a url prefix and then the filename at the end. ... (4 Replies)
Discussion started by: jason7
4 Replies

10. Shell Programming and Scripting

Parse an XML task list to create each task.xml file

I have an task definition listing xml file that contains a list of tasks such as <TASKLIST <TASK definition="Completion date" id="Taskname1" Some other <CODE name="Code12" <Parameter pname="Dog" input="5.6" units="feet" etc /Parameter> <Parameter... (3 Replies)
Discussion started by: MissI
3 Replies
Login or Register to Ask a Question