On Nov 28, 3:50 pm, woodyee <wood_ye... / hotmail.com> wrote:
> On Nov 28, 2:00 pm, yermej <yer... / gmail.com> wrote:
>
> > On Nov 28, 8:38 am, woodyee <wood_ye... / hotmail.com> wrote:
>
> > > Hi! I had to manually remove decimals and tildes from a text file. How
> > > could I have done this via programming? I googled this but didn't
> > > really find anything, just stuff on removing spaces. Basically, I'd
> > > like to be able to search a file and remove certain items (ex - all
> > > decimals and tildes). Thanks!
>
> > This will remove all decimals and tildes and create a backup of the
> > original file with the extension .bak (from the command line):
>
> > ruby -i.bak -n -e 'print $_.gsub(/[\.~]/, "")' input_file.txt
>
> > Jeremy
>
> WOW! It worked and it was so cool!! Thanks! One thing I did - I
> modified it to delete the .00's:
>
> ruby -i.bak -n -e 'print $_.gsub(/[\.00~]/, " ")' input_file.txt
>
> This worked but it deleted the zero in front of the decimal. How can I
> avoid this? Thanks!  :-)

Typically, when you characters in [], it means to match any character
in that group. So, [\.00~] is the same as [\.0~] is the same as [0\.~]
etc. so you removed all occurrences of 0, ., and ~ no matter what
surrounded them.

If you want to delete just .00 and ~, try:

/\.00|~/

as the first argument to gsub. That means match .00 or ~ and nothing
else.

This is probably a decent site if you want to learn more about regular
expressions:
http://www.regular-expressions.info/tutorial.html

Jeremy