Subject: RE: regular expressions and a text file
From: Mike Barsalou (mbarsalou@aidea.org)
Date: Fri Aug 23 2002 - 14:00:14 AKDT
Thanks for the responses guys, that worked great.
-----Original Message-----
From: Peter Q. Olsson [mailto:olsson@koyukuk.at.uaa.alaska.edu]
Sent: Friday, August 23, 2002 12:42 PM
To: mbarsalou@aidea.org
Subject: Re: regular expressions and a text file
Kike-
I think the Regexp you were using was missing a + quantifier. "\s+" matches
one or more contiguous white spaces.
Like the perl script below:
#################################
#!/usr/local/bin/perl
$file_name=$ARGV[0];
open(FILE,$file_name) or die "can't open $file_name\n";
while(<FILE>)
{
chomp;
@a=split /\s+/;
}
print join("-",@a),"\n";
close FILE;
######################################
which outputs the string:
"data1-data2-data3-data4"
on the example you gave. (Of course, you wanted to probably do something
more
with the split fields that this...)
PQO
>We have a text file we are trying to parse....each data item is separated
by
>a tab...sometimes.
>
>Is there regular expression I can use that would swallow up all of the tabs
>and whitespaces? Will it work in the split command? or will I have to
>process the line first, then hand it to the split command?
>
>For example the data looks like:
>
>data1\t\tdata2\t data3 data4
>
>
>And the combinations of tabs and spaces is not consistent from line to line
>(what a nightmare).
>
>We tried using
>
>split(/\s/,$line);
>
>But this didn't do what we expected...we were hoping the \s would swallow
>all of the whitespace characters.
>
>Mike
>
>---------
>To unsubscribe, send email to <aklug-request@aklug.org>
>with 'unsubscribe' in the message body.
>
__________________________________________________________________
| |
| Dr. Peter Q. Olsson, |
| Chief Scientist, Alaska Experimental Forecast Facility |
| University of Alaska Anchorage |
| 2811 Merrill Field Drive |
| Anchorage, AK 99501 |
| voice: (907) 264-7449 |
| fax : (907) 264-7444 |
| olsson@aeff.at.uaa.alaska.edu |
|__________________________________________________________________|
---------
To unsubscribe, send email to <aklug-request@aklug.org>
with 'unsubscribe' in the message body.
This archive was generated by hypermail 2a23 : Fri Aug 23 2002 - 14:02:52 AKDT