Using regular expressions to insert tags

[email protected] (Sriram Rajagopalan) Tue, 20 Jun 2006 10:19:18 -0400
Newsgroups perl.scripts
Message-ID <[email protected]>
------_=_NextPart_001_01C69474.83FA386E
Content-Type: text/plain

Hello,

I have a text file in a columnar format. There are seven entries in a row,
separated by tabs.

eg.

1	23	555	34	Corporation	Index	Sediment

This has to be tagged as:
<no>1</no><code>23</code><set>555</set><id>34</id><status>Corporation</statu
s><value>Index</value><type>Sediment</type>

I have stored the file contents to $_ and I am using the regex

$_=~s/([^\t]*)\t([^\t]*)\t([^\t]*)\t([^\t]*)\t([^\t]*)\t([^\t]*)\t([^\t]*)\t
/<no>$1<\/no><code>$2<\/code><set>$3<\/set><id>$4<\/id><status>$5<\/status><
value>$6<\/value><type>$7<\/type>/g;

I am not able to get the text tagged. Can anyone help me out to get my
desired codes?

Thanks,
Sriram

------_=_NextPart_001_01C69474.83FA386E
Content-Type: text/html
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =
charset=3Dus-ascii">
<META NAME=3D"Generator" CONTENT=3D"MS Exchange Server version =
5.5.2658.2">
<TITLE>Using regular expressions to insert tags</TITLE>
</HEAD>
<BODY>

<P ALIGN=3DLEFT><FONT SIZE=3D2 FACE=3D"Verdana">Hello,</FONT></P>

<P ALIGN=3DLEFT><FONT SIZE=3D2 FACE=3D"Verdana">I have a text file in a =
columnar format. There are seven entries in a row, separated by =
tabs.</FONT></P>

<P ALIGN=3DLEFT><FONT SIZE=3D2 FACE=3D"Verdana">eg.</FONT></P>

<P ALIGN=3DLEFT><FONT SIZE=3D2 =
FACE=3D"Verdana">1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
23&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 555&nbsp;&nbsp;&nbsp;&nbsp; =
34&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Corporation&nbsp;&nbsp;&nbsp;&nbsp; =
Index&nbsp;&nbsp; Sediment</FONT></P>

<P ALIGN=3DLEFT><FONT SIZE=3D2 FACE=3D"Verdana">This has to be tagged =
as:</FONT></P>

<P ALIGN=3DLEFT><FONT SIZE=3D2 =
FACE=3D"Verdana">&lt;no&gt;1&lt;/no&gt;&lt;code&gt;23&lt;/code&gt;&lt;se=
t&gt;555&lt;/set&gt;&lt;id&gt;34&lt;/id&gt;&lt;status&gt;Corporation&lt;=
/status&gt;&lt;value&gt;Index&lt;/value&gt;&lt;type&gt;Sediment&lt;/type=
&gt;</FONT></P>

<P ALIGN=3DLEFT><FONT SIZE=3D2 FACE=3D"Verdana">I have stored the file =
contents to $_ and I am using the regex</FONT></P>

<P ALIGN=3DLEFT><FONT SIZE=3D2 =
FACE=3D"Verdana">$_=3D~s/([^\t]*)\t([^\t]*)\t([^\t]*)\t([^\t]*)\t([^\t]*=
)\t([^\t]*)\t([^\t]*)\t/&lt;no&gt;$1&lt;\/no&gt;&lt;code&gt;$2&lt;\/code=
&gt;&lt;set&gt;$3&lt;\/set&gt;&lt;id&gt;$4&lt;\/id&gt;&lt;status&gt;$5&l=
t;\/status&gt;&lt;value&gt;$6&lt;\/value&gt;&lt;type&gt;$7&lt;\/type&gt;=
/g;</FONT></P>

<P ALIGN=3DLEFT><FONT SIZE=3D2 FACE=3D"Verdana">I am not able to get =
the text tagged. Can anyone help me out to get my desired =
codes?</FONT></P>

<P ALIGN=3DLEFT><FONT SIZE=3D2 FACE=3D"Verdana">Thanks,</FONT></P>

<P ALIGN=3DLEFT><FONT SIZE=3D2 FACE=3D"Verdana">Sriram</FONT></P>

</BODY>
</HTML>
------_=_NextPart_001_01C69474.83FA386E--