Solved

Data to XML Formatting

Posted on 2010-09-15
5
390 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
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…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

760 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

22 Experts available now in Live!

Get 1:1 Help Now