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]

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


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: Use Regular Expressions to replace words/strings of characters in a text file
Date   Wed, 15 Aug 2012 18:20:53 +0100

No and no. -filefilter- is only part of the answer. If your problems
were mine, I would be processing the file with -file- statements. You
would have to read in each line and process it. That could include
setting markers for when you are in certain parts of the file and are
prepared to make particular changes.

There is no objection, naturally, to do your doing that with any
scripting language you know. But my impression is that your problem is
programmable in Stata.

Nick

On Wed, Aug 15, 2012 at 4:59 PM, tashi lama <[email protected]> wrote:
> Thanx. This is great although it seems that its options are limited. Are there ways to pull the followings around
> 1. filefilter tt1.xml tt2.xml, from("Worksheet") to("") removes worksheet from the file. What if I have a block of characters that I need to remove? Is there a way to say like I want all the characters removed that occur before string table( first occurence of table since there might be multiple strings table in the text)?
> 2. This might be a redundant of the last part of the first question. Since there are no options in filefilter saying look the pattern only from here to here like in subinstr("fafaa","a","t",1) to mean replace first a  or subinstr("fafaa","a","t",.) to mean replace all a, is there a way to do search and replace for only part of the text?
>
> Thanx tons..
> Tashi
> -----------------------------
>> Date: Wed, 15 Aug 2012 01:07:39 +0100
>> Subject: Re: st: Use Regular Expressions to replace words/strings of characters in a text file
>> From: [email protected]
>> To: [email protected]
>>
>> -help filefilter-
>>
>> Nick
>>
>> On Tue, Aug 14, 2012 at 9:18 PM, tashi lama <[email protected]> wrote:
>>
>> > 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"
>>
>> *
>> * 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/
> *
> *   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/

*
*   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