Solved

Data to XML Formatting

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
IE 11 + long running scripts 3 74
Debugging a shell script 3 31
Check for Linux process in script 7 47
how to include conditional log rotate in liunx. 17 35
This Windows batch file is useful for organizing image files from a digital camera or other source, but can have many other uses.  It simply renames the file(s) to match their create date.  For example, if you took a picture today at 1:40pm and the …
Over the years I've spent many an hour playing on hardened, DMZ'd servers, with only a sub-set of the usual GNU toy's to keep me company; frequently I've needed to save and send log or data extracts from these server back to my PC, or to others, and…
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

860 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