Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Using perl -e to remove times/dates from a file

Reply
Thread Tools

Using perl -e to remove times/dates from a file

 
 
Paul Tomlinson
Guest
Posts: n/a
 
      11-28-2003
All I have a file called "DirList.txt" which was generated by redirecting
the results of a DOS dir to a file.

What I want is to have perl remove the times (and preferably dates) from
this file.

I thought I could do it like such but it appears to do nothing, any
pointers?

c:\perl\bin\perl.exe -e tr/09:36//; "c:\DirList.txt"

I know that this will only translate the time 09:36 to null but for now
anything is a start.

PT


 
Reply With Quote
 
 
 
 
Ben Liddicott
Guest
Posts: n/a
 
      11-28-2003
Hi Paul,

You need an introduction to regular expressions.

The translation operator:

tr/09:36//

will remove all "0", "9", ":", "3" and "6" characters. It is really to be used for counting characters or tr/a-z/A-Z/ and suchlike.

You need to be looking at the s/find/replace/ regex operator.

perldoc perlrequick
perldoc perlretut

Cheers,
Ben Liddicott

"Paul Tomlinson" <(E-Mail Removed)> wrote in message news:bq77c5$1vbnc1$(E-Mail Removed)-berlin.de...

> All I have a file called "DirList.txt" which was generated by redirecting
> the results of a DOS dir to a file.
>
> What I want is to have perl remove the times (and preferably dates) from
> this file.
>


 
Reply With Quote
 
 
 
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      11-28-2003
Paul Tomlinson wrote:
> All I have a file called "DirList.txt" which was generated by
> redirecting the results of a DOS dir to a file.
>
> What I want is to have perl remove the times (and preferably dates)
> from this file.


If it's not too late, and to create a file with only the file names,
wouldn't something like this be better:

open FH, '> DirList.txt' or die $!;
opendir DIR, '.' or die $!;
print FH join "\n", readdir DIR;
closedir DIR or die $!;
close FH or die $!;

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

 
Reply With Quote
 
Paul Tomlinson
Guest
Posts: n/a
 
      11-28-2003
Thanks i've sorted it Bernards answer more-or-less sorted me out.
"Gunnar Hjalmarsson" <(E-Mail Removed)> wrote in message
news:bq7cs0$1t9mbe$(E-Mail Removed)-berlin.de...
> Paul Tomlinson wrote:
> > All I have a file called "DirList.txt" which was generated by
> > redirecting the results of a DOS dir to a file.
> >
> > What I want is to have perl remove the times (and preferably dates)
> > from this file.

>
> If it's not too late, and to create a file with only the file names,
> wouldn't something like this be better:
>
> open FH, '> DirList.txt' or die $!;
> opendir DIR, '.' or die $!;
> print FH join "\n", readdir DIR;
> closedir DIR or die $!;
> close FH or die $!;
>
> --
> Gunnar Hjalmarsson
> Email: http://www.gunnar.cc/cgi-bin/contact.pl
>



 
Reply With Quote
 
Eric J. Roode
Guest
Posts: n/a
 
      11-28-2003
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

"Paul Tomlinson" <(E-Mail Removed)> wrote in news:bq77c5$1vbnc1$1
@ID-116287.news.uni-berlin.de:

> All I have a file called "DirList.txt" which was generated by redirecting
> the results of a DOS dir to a file.
>
> What I want is to have perl remove the times (and preferably dates) from
> this file.


On my windows 2000 computer, "dir /b" gives me just a bare list of
filenames. I don't know if this option is available on all versions of
dos/windows, but if it is, it'll be easier for you to change your input
than to post-process it with Perl.

- --
Eric
$_ = reverse sort $ /. r , qw p ekca lre uJ reh
ts p , map $ _. $ " , qw e p h tona e and print

-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>

iQA/AwUBP8dcUWPeouIeTNHoEQIoIACgmZ7xcE1mBTwjjnrsI8CsBp NtrRIAn1AW
xO8vdGMYS3Ab7M1J1M6OIH/b
=5n/i
-----END PGP SIGNATURE-----
 
Reply With Quote
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      11-28-2003
Eric J. Roode wrote:
> On my windows 2000 computer, "dir /b" gives me just a bare list of
> filenames. I don't know if this option is available on all
> versions of dos/windows, but if it is, it'll be easier for you to
> change your input than to post-process it with Perl.


I tested on W98, and it worked there, too.

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

 
Reply With Quote
 
Michele Dondi
Guest
Posts: n/a
 
      11-28-2003
On Fri, 28 Nov 2003 10:16:15 -0000, "Paul Tomlinson"
<(E-Mail Removed)> wrote:

>All I have a file called "DirList.txt" which was generated by redirecting
>the results of a DOS dir to a file.
>
>What I want is to have perl remove the times (and preferably dates) from
>this file.


perl -lpi.bak -e "s|\d{2}/d{2}/\d{2}\s+\d+.\d{2}||" DirList.txt

or some reasonable variation. But isn't it that you really needed

dir /b

>c:\perl\bin\perl.exe -e tr/09:36//; "c:\DirList.txt"
>
>I know that this will only translate the time 09:36 to null but for now
>anything is a start.


NO! It will do something different.


Michele
--
# This prints: Just another Perl hacker,
seek DATA,15,0 and print q... <DATA>;
__END__
 
Reply With Quote
 
Michele Dondi
Guest
Posts: n/a
 
      11-29-2003
On Fri, 28 Nov 2003 08:30:57 -0600, "Eric J. Roode"
<(E-Mail Removed)> wrote:

>On my windows 2000 computer, "dir /b" gives me just a bare list of
>filenames. I don't know if this option is available on all versions of
>dos/windows, but if it is, it'll be easier for you to change your input
>than to post-process it with Perl.


It exists at least since MS-DOS 5.0, that is the first version I
"worked" with.


Michele
--
# This prints: Just another Perl hacker,
seek DATA,15,0 and print q... <DATA>;
__END__
 
Reply With Quote
 
Dave Weaver
Guest
Posts: n/a
 
      12-01-2003
On Fri, 28 Nov 2003 11:11:15 -0000, Ben Liddicott
<(E-Mail Removed)> inconsiderately top-posted:
>
> The translation operator:
>
> tr/09:36//
>
> will remove all "0", "9", ":", "3" and "6" characters.


No it won't.

[davew]$ perl
$x = "12:34:56";
$x =~ tr/09:36//;
print "x = $x\n";
__END__
x = 12:34:56
[davew]$

"perldoc perlop" for more info.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Remove linebreaks from a XML file using Perl yann.pambou@gmail.com Perl Misc 2 11-21-2005 06:17 AM
How to remove extra lines in a XML file using perl pambouy2@hotmail.com Perl Misc 4 11-21-2005 12:48 AM
Httpmodule still executed even if remove using <remove> config entry Simon-Pierre Jarry ASP .Net 2 08-10-2005 11:22 AM
Remove javascript content from HTML page using Perl Mark Perl 1 08-12-2004 06:20 PM
How to remove ^M using perl ? Abhinav Perl Misc 5 05-26-2004 05:17 PM



Advertisments