Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: Use Regular Expressions to replace words/strings of characters in a text file


From   tashi lama <[email protected]>
To   <[email protected]>
Subject   st: Use Regular Expressions to replace words/strings of characters in a text file
Date   Tue, 14 Aug 2012 20:18:54 +0000

Hello all, 
    I looked for previous posts and read and still can't find the solution. I could use stata's string functions(regexr, subinstr etc) to search and replace string in a string. But if I have a text file(test1.xml) that I need to run a search and replace on, how do I do it? Putting a text in a local macro( put aside the macro limitation)  and using regexr wouldn't be an option because I have to generate a  xml file from the dataset. 

view test1.xml

<?xml version="1.0" encoding="US-ASCII" standalone="yes"?>
<?mso-application progid="Excel.Sheet"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
 xmlns:o="urn:schemas-microsoft-com:office:office"
 xmlns:x="urn:schemas-microsoft-com:office:excel"
 xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
 xmlns:html="http://www.w3.org/TR/REC-html40";>
<DocumentProperties xmlns="urn:schemas-microsoft-com:office:office">
<Author></Author>
<LastAuthor></LastAuthor>
<Created></Created>
<LastSaved></LastSaved>
<Company></Company>
<Version></Version>
</DocumentProperties>
<ExcelWorkbook  xmlns="urn:schemas-microsoft-com:office:excel">
<ProtectStructure>False</ProtectStructure>
<ProtectWindows>False</ProtectWindows>
</ExcelWorkbook>
<Styles>
<Style ss:ID="s1">
<Alignment ss:Horizontal="Center" ss:Vertical="Bottom"/>
<Font ss:Bold="1"/>
<NumberFormat/>
</Style>
</Styles>
<Names>
</Names>
<Worksheet ss:Name="Sheet1">
<Table ss:ExpandedColumnCount="3" ss:ExpandedRowCount="7"
 x:FullColumns="1" x:FullRows="1">
<Row>
<Cell ss:StyleID="s1"><Data ss:Type="String">a</Data></Cell>
<Cell ss:StyleID="s1"><Data ss:Type="String">b</Data></Cell>
<Cell ss:StyleID="s1"><Data ss:Type="String">c</Data></Cell>
</Row>
<Row>
<Cell><Data ss:Type="Number">0.000000</Data></Cell>
<Cell><Data ss:Type="Number">1.000000</Data></Cell>
<Cell><Data ss:Type="Number">15.000000</Data></Cell>
</Row>

I need to search for "Row" and "Cell" in the text and replace with "TR" and "TD" respectively. I also have to delete every character that arises before string "table". Can Stata do this or  I need to ask Perl to do it? Any help will be highly appreciated?

Thanx tons 		 	   		  
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index