Solved

Data to XML

Posted on 2010-09-20
6
655 Views
Last Modified: 2013-11-15
Hi,

I'm looking for a way to convert a list of domain lists to XML format.

Example:

domain.com     number    number     number     number
domain.com     number    number     number     number
domain.com     number    number     number     number
domain.com     number    number     number     number
domain.com     number    number     number     number
domain.com     number    number     number     number

Desired Output:

                <tr class="gradeA">
                  <td>domain</td>
                  <td>number</td>
                  <td>number</td>
                  <td class="center">number</td>

                  <td class="center">number</td>
            </tr>
      <tr class="gradeA">
                  <td>domain</td>
                  <td>number</td>
                  <td>number</td>
                  <td class="center">number</td>

                  <td class="center">number</td>
            </tr>
      <tr class="gradeA">
                  <td>domain</td>
                  <td>number</td>
                  <td>number</td>
                  <td class="center">number</td>

                  <td class="center">number</td>
            </tr>
      <tr class="gradeA">
                  <td>domain</td>
                  <td>number</td>
                  <td>number</td>
                  <td class="center">number</td>

                  <td class="center">number</td>
            </tr>

Thank you
0
Comment
Question by:faithless1
  • 4
  • 2
6 Comments
 
LVL 84

Expert Comment

by:ozo
Comment Utility
awk 'print awk '{print "<tr class=\"gradeA\">\n<td>"$1"</td>\n<td>"$2"</td>\n<td>"$3"</td>\n<td class=\"center\">"$4"</td>\n<td class=\"center\">"$5"</td>"}'
0
 
LVL 84

Expert Comment

by:ozo
Comment Utility
awk '{print "<tr class=\"gradeA\">\n<td>"$1"</td>\n<td>"$2"</td>\n<td>"$3"</td>\n<td class=\"center\">"$4"</td>\n<td class=\"center\">"$5"</td>"}'
0
 
LVL 15

Expert Comment

by:mish33
Comment Utility

#!/usr/bin/python
import sys
for line in open(sys.stdin):
  domain, n1, n2, n3, n4 = line.split()
  print '''\
           <tr class="gradeA">
                  <td>%s</td>
                  <td>%s</td>
                  <td>%s</td>
                  <td class="center">%s</td>

                  <td class="center">%s</td>
            </tr>
''' % (domain.rsplit('.', 1)[0], n1, n2, n3, n4)

Open in new window

0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 84

Accepted Solution

by:
ozo earned 500 total points
Comment Utility
perl -ane 'printf q(   <tr class="gradeA">
                  <td>%s</td>
                  <td>%s</td>
                  <td>%s</td>
                  <td class="center">%s</td>

                  <td class="center">%s</td>
            </tr>
),@F'  
0
 
LVL 15

Expert Comment

by:mish33
Comment Utility
.com not cut away :)
0
 
LVL 84

Expert Comment

by:ozo
Comment Utility
perl -ane '$F[0]=~s/\.com$//;printf q(   <tr class="gradeA">
                  <td>%s</td>
                  <td>%s</td>
                  <td>%s</td>
                  <td class="center">%s</td>

                  <td class="center">%s</td>
            </tr>
),@F'  
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now