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 = 23 555 = 34 Corporation = Index 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"><no>1</no><code>23</code><se= t>555</set><id>34</id><status>Corporation<= /status><value>Index</value><type>Sediment</type= ></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/<no>$1<\/no><code>$2<\/code= ><set>$3<\/set><id>$4<\/id><status>$5&l= t;\/status><value>$6<\/value><type>$7<\/type>= /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--