Computing.Net > Forums > Programming > Batch to del specific lines in txt

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Batch to del specific lines in txt

Reply to Message Icon

Name: pekmd
Date: October 18, 2005 at 10:38:00 Pacific
OS: windows xp sp2
CPU/Ram: amd xp 2600+ 1GB ram
Comment:

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



Sponsored Link
Ads by Google

Response Number 1
Name: IVO
Date: October 18, 2005 at 12:30:24 Pacific
Reply:

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.


0

Response Number 2
Name: pekmd
Date: October 18, 2005 at 16:13:34 Pacific
Reply:

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


0

Response Number 3
Name: Mechanix2Go
Date: October 18, 2005 at 16:44:33 Pacific
Reply:

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


0

Response Number 4
Name: FishMonger
Date: October 18, 2005 at 16:44:33 Pacific
Reply:

#!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


0

Response Number 5
Name: Mechanix2Go
Date: October 18, 2005 at 16:51:08 Pacific
Reply:

Hi FM,

How do you get the "euro" into the script?


If at first you don't succeed, you're about average.

M2


0

Related Posts

See More



Response Number 6
Name: FishMonger
Date: October 18, 2005 at 16:59:58 Pacific
Reply:

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.


0

Response Number 7
Name: Mechanix2Go
Date: October 18, 2005 at 17:10:29 Pacific
Reply:

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


0

Response Number 8
Name: FishMonger
Date: October 18, 2005 at 17:14:28 Pacific
Reply:

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?


0

Response Number 9
Name: Mechanix2Go
Date: October 18, 2005 at 17:21:30 Pacific
Reply:

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


0

Response Number 10
Name: pekmd
Date: October 18, 2005 at 17:28:21 Pacific
Reply:

worked like a charm fishmonger! thx alot guys :P


0

Response Number 11
Name: FishMonger
Date: October 18, 2005 at 17:38:17 Pacific
Reply:

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?


0

Response Number 12
Name: FishMonger
Date: October 18, 2005 at 17:41:17 Pacific
Reply:

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.


0

Response Number 13
Name: pekmd
Date: October 18, 2005 at 23:53:28 Pacific
Reply:

that would be cool :)
waiting for ur reply :P


0

Response Number 14
Name: Mechanix2Go
Date: October 19, 2005 at 00:25:17 Pacific
Reply:

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


0

Response Number 15
Name: FishMonger
Date: October 19, 2005 at 08:23:31 Pacific
Reply:

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.


0

Response Number 16
Name: FishMonger
Date: October 19, 2005 at 13:26:05 Pacific
Reply:

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";
}


0

Response Number 17
Name: FishMonger
Date: October 19, 2005 at 13:28:41 Pacific
Reply:

print F $line  if $line =~ /€$/;

should read
print F $line if $line =~ /€$/;


This site is a pain in !@#$%^ when posting code


0

Response Number 18
Name: pekmd
Date: October 21, 2005 at 12:39:42 Pacific
Reply:

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


0

Response Number 19
Name: ebrian
Date: November 4, 2005 at 08:27:40 Pacific
Reply:

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.


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Batch to del specific lines in txt

batch edit specific line in txt www.computing.net/answers/programming/batch-edit-specific-line-in-txt/16778.html

echo text to specific line in file www.computing.net/answers/programming/echo-text-to-specific-line-in-file/11965.html

Reading Specific Lines in C++ www.computing.net/answers/programming/reading-specific-lines-in-c/2843.html