Solved

Data to XML Formatting

Posted on 2010-09-15
5
391 Views
Last Modified: 2013-12-26
Hi,

I have about 500k records of data, here's a sample:

doubleclick.net      172823613      Services      Ad Networks and Servers      
atdmt.com      162598392      Services      Ad Networks and Servers      
trafficmp.com      148660547      Services      Ad Networks and Servers      
specificmedia.com      144601453      Services      Ad Networks and Servers      
tribalfusion.com      135750347      Services      Ad Networks and Servers      
yieldmanager.com      135224700      Services      Ad Networks and Servers      
realmedia.com      105436510      Services      Ad Networks and Servers      
interclick.com      102619007      Services      Ad Networks and Servers      

I'm interested in outputting the following, where <tr id="number"> will increase for each set of data.

<tr id="1">
<td>9/1/2010</td>
<td>doubleclick.net</td>
<td>172823280</td>
<td>Services</td>
<td>Ad Networks and Servers</td>
</tr>
<tr id="2">
<td>9/1/2010</td>
<td>atdmt.com</td>
<td>162598059</td>
<td>Services</td>
<td>Ad Networks and Servers</td>
</tr>
<tr id="3">
<td>9/1/2010</td>
<td>trafficmp.com</td>
<td>148660214</td>
<td>Services</td>
<td>Ad Networks and Servers</td>
</tr>
<tr id="4">
<td>9/1/2010</td>
<td>specificmedia.com</td>
<td>144601120</td>
<td>Services</td>
<td>Ad Networks and Servers</td>
</tr>
<tr id="5">
<td>9/1/2010</td>
<td>yieldmanager.com</td>
<td>135224367</td>
<td>Services</td>
<td>Ad Networks and Servers</td>
</tr>
<tr id="6">
<td>9/1/2010</td>
<td>realmedia.com</td>
<td>105436177</td>
<td>Services</td>
<td>Ad Networks and Servers</td>
</tr>
<tr id="7">
<td>9/1/2010</td>
<td>interclick.com</td>
<td>102618674</td>
<td>Services</td>
<td>Ad Networks and Servers</td>
</tr>

Thank you
0
Comment
Question by:faithless1
  • 3
  • 2
5 Comments
 
LVL 29

Expert Comment

by:MikeOM_DBA
ID: 33681612
Assuming the source file delimiter is "tab", try this:


crdt=`date +%m\/%d\/%y`
awk -F"\t" -v dt=$crdt '{
print "<tr id=\""++t"\">"
print "<td>"dt"</td>"
print "<td>"$1"</td>"
print "<td>"$2"</td>"
print "<td>"$3"</td>"
print "<td>"$4"</td>"
print "</tr>"
}' MyFile.txt

Open in new window

0
 

Author Comment

by:faithless1
ID: 33698498
Hi,

Just ran this on the command line and got the following error: line 1: syntax error at or near print


cat test.txt | crdt=`date +%m\/%d\/%y`| awk -F"\t" -v dt=$crdt '{print "<tr id=\""++t"\">"print "<td>"dt"</td>"print "<td>"$1"</td>"print "<td>"$2"</td>"print "<td>"$3"</td>"print "<td>"$4"</td>"print "</tr>"}'
awk: line 1: syntax error at or near print
0
 

Author Comment

by:faithless1
ID: 33698499
Hi,

Just ran this on the command line and got the following error: line 1: syntax error at or near print


cat test.txt | crdt=`date +%m\/%d\/%y`| awk -F"\t" -v dt=$crdt '{print "<tr id=\""++t"\">"print "<td>"dt"</td>"print "<td>"$1"</td>"print "<td>"$2"</td>"print "<td>"$3"</td>"print "<td>"$4"</td>"print "</tr>"}'
awk: line 1: syntax error at or near print
0
 
LVL 29

Expert Comment

by:MikeOM_DBA
ID: 33700642
You are missing semi-colons between the awk statements, try executing in a script..

0
 
LVL 29

Accepted Solution

by:
MikeOM_DBA earned 500 total points
ID: 33700698

#
# Try this code in a script:
#
crdt=`date +%m\/%d\/%y`; 
awk -F"\t" -v dt=$crdt '{
print "<tr id=\""++t"\">";
print "<td>"dt"</td>";
for (i=1;i<=NF;++i) print "<td>"$i"</td>";
print "</tr>";
}' test.txt
#
# Or this in one line:
#
crdt=`date +%m\/%d\/%y`; awk -F"\t" -v dt=$crdt '{print "<tr id=\""++t"\">";print "<td>"dt"</td>";for (i=1;i<=NF;++i) print "<td>"$i"</td>";print "</tr>";}' test.txt
#

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
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…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

910 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

18 Experts available now in Live!

Get 1:1 Help Now