Bookmark and Share

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

[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 <>
To   <>
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"
<DocumentProperties xmlns="urn:schemas-microsoft-com:office:office">
<ExcelWorkbook  xmlns="urn:schemas-microsoft-com:office:excel">
<Style ss:ID="s1">
<Alignment ss:Horizontal="Center" ss:Vertical="Bottom"/>
<Font ss:Bold="1"/>
<Worksheet ss:Name="Sheet1">
<Table ss:ExpandedColumnCount="3" ss:ExpandedRowCount="7"
 x:FullColumns="1" x:FullRows="1">
<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>
<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>

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:

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