Page 1 of 1

ot - I need a geek (regexps or similar)

Posted: Sun Jan 07, 2007 2:50 pm
by noisetonepause
Hello, Forum!

I've got a small problem.

I'm writing an essay for school(uni) and I want to do the typesetting in (Te)TeX, cos it renders things all lovely, and I need to put a few arabic words in there and TeTeX, well, renders Arabic transliteration all lovely:)

I've just written plain text files, but now I need to do some pattern replacements for my footnotes. Basically in my text files I've got the pattern (NOTE: ...text...) which I need to replace with \footnote{...text...}.

I know I can do this with regexps in my editor easier than standard search & replace, but I'm not sure exactly how it works.

I've got Unix sed and awk and what have ye as well, but I don't know how to use them.

If anyone could give me some pointers, I'd be much full of grate.

Tar,
Paws

Posted: Sun Jan 07, 2007 8:38 pm
by earsmack
There are plenty of real good regex tutorials (using a variety of apps) online - google it.

Posted: Sun Jan 07, 2007 10:50 pm
by bandbajao
man, this topic is waaay OT :lol:

if the text you need to search for is -
(NOTE: ...text...)
then search for ^\(NOTE:(.+)\)$
and replace with \footnote{$1}

if the text you need to search for is -
NOTE: ...text...
then search for ^NOTE:(.+)$
and replace with \footnote{$1}

this is posix. if you're using textpad, use \1 instead of $1 in the replacement expression.

Posted: Mon Jan 08, 2007 12:03 am
by MrYellow
Yeah music by regexp!

[T][o]{2} [C][o]{2}[l]

-Ben

Posted: Mon Jan 08, 2007 2:04 am
by mikemc
get perl. if it is a small text file, then

(your standard perl heading goes here)

$pattern= the old thing; # you need to escape this properly
$newpattern = the new thing; # same as above

while(1){
$modifiedString = $_;
$modifiedString =~ s/$pattern/$newpattern/g;
print $modifiedString;
}

pipe the text file to the above script

Posted: Wed Jan 10, 2007 3:22 am
by noisetonepause
Thanks all.

The essay turned out beautiful... typographically speaking, at least:)

Must learn to start earlier!