Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
hi guys!
i've been reading this forum and found it very informative!
Im looking for a batch that will delete all lines in a txt file except the lines that end with a €
Any help will be greatly appreciated , thx in advance

Apparently simple, but indeed a nasty challenge, as the batch scripting is a legacy of (and aimed to) DOS environment where characters are coded by ASCII and ruled by CodePage (437, 850 and so on...).
Now € symbol is born well after the sunset of DOS and so trying to use it in a DOS box under Windows leads you to unexpected results.
Better you avoid at all that lane.

maybe with a perl script?
if someone could help me would be great, cause i have very big txt files to clean :(

Maybe perl, but I don't know anything about it.
As IVO indicates, it's not strictly speaking, text.
Maybe open it in excel and create a filter.
If at first you don't succeed, you're about average.M2

#!perl -w
open F, 'file.txt' or die $!;
while (<F>) { print if /€$/; }
close F;
Assuming the script is named filter.pl and your txt file is named file.txt, you'd execute it like this:C:>filter.pl file.txt > filtered.txt

Hi FM,
How do you get the "euro" into the script?
If at first you don't succeed, you're about average.M2

Actually, the script can be reduced to this:
#!perl -w
while (<>) { print if /€$/; }
>> How do you get the "euro" into the script?
In this case, I just copied/pasted it from this post. I could have used its unicode value but I didn't know it and didn't take the time to look it up.

Hi FM,
UH...
If I knew the unicode, how would I get it into the script?
If at first you don't succeed, you're about average.M2

Hi M2,
I'm not sure I know what you mean. Are you asking what the syntax would be if you wanted to use the unicode?

Hi FM,
I guess I'm too simple minded.
How can I type the "euro" into a script?
If at first you don't succeed, you're about average.M2

This is the way I did it:
I viewed the source of this web page to see if the "euro" characture was html encoded (which it wasn't).
I highlighted it and pressed ctrl-c to copy it into the clipboard.
I went to my text editor (textpad) and pressed ctrl-v to past it.
Note: notepad won't reconize the characture.
Does that answer your question?

pekmd,
If you have lots of files, I can show you how to loop through them, so you don't have to execute the script for each one of them.

Hi FM,
Got it.
Thanks.
Interestingly, w2k notepad DOES recognize it. I wouldn't have thought so.
If at first you don't succeed, you're about average.M2

M2,
That's interesting. My W2K notepad didn't recognize it but wordpad did.
pekmd,
If you can give me a sample of your file structure that you need to apply this to (meaning, are all files in the same dir and have the same ext), it would help me to write a proper script that you won't need to adjust to your needs.

Here's the more verbose version that processes/updates all of the .txt files in the current dir and provides a little feed back to the user.
#!perl -w
use strict;
@ARGV = <*.txt>;
foreach my $file (@ARGV) {
    print "Processing $file ... Please Wait\n";
    open F, $file or die "can't read from $file $!";
    my @contents = <F>;
    close F;
    open F, ">$file" or die "can't write to $file $!";
    foreach my $line (@contents) {
       print F $line       if $line =~ /€$/;
    }
    close F;
    print "Competed processing $file\n\n";
}

print F $line  if $line =~ /€$/;
should read
print F $line if $line =~ /€$/;
This site is a pain in !@#$%^ when posting code

all the files r in the same dir, and all r .txt
ill test ur new code tonight and tell u the results..

As an alternative to capture the euro symbol, you can also use Windows Character Map to copy and paste the symbol into notepad. When I copy it into notepad and echo it out I receive the following:
'echo €' produces U:\>echo Ç
Cool think about the character map, it will also give you the Alt-keystroke to obtain the various ASCII symbols.

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |