Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Handle White Space in File Path 5

Status
Not open for further replies.

ickypick

IS-IT--Management
Sep 1, 2006
9
0
0
US
Hi All,
I have a parser that reads in ftp logs and does an insert into a database. Everything parses, and inserts fine. However, on occasion, a user has created a file or file path with whitespace in the name, i.e. - "/userhome/my files/bigfile".
The parser picks up the whitespace between "my files" in this example and the variable $path is incomplete and all other variables shift over. Therefore the wrong data is inserted into the wrong table in the database. Does anyone have a suggestion on how to check for whitespace in the file path and account for it? Is there a way to ignore the white space for this place in the log file only? Any help is appreciated =)

Here is the snippet of code for reading the log file:


#while (<>) {
while (<FILE>) {
($dow, $month, $day, $time, $year, $duration, $clientip, $size, $path, $ttype, $specialact, $type, $mode, $uid, $service, $authm, $authu, $status) = split(/\s+/);

Thanks in advance.

Icky
 
Well, all that code we came up with is based on just two lines of data. Your data file must have lines in it that are different than the two sample lines.
 
Kevin the code was red the output was wrong, but thanks.

The sample code I posted worked, is all I'm sayin' :p
/note to self, go straight to bed ... and sudoku, meh ;-)

<rant> Who do we go to to syndicate a perl puzzle in our local papers, now there's a good question..., perl's more productive than sudoku ... isn't it?, 33,00 out of a 250,000 people getting the result right, no word of how many wasted minutes of humanity were spent on the whim of an editor who said "I know, I've got a great idea, there's this thing ..."</rant>

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
I agree guys, the sample code posted worked fine. The data is the same, because I created a test data file with only one entry in it:

myhost# ./test.pl -d test
reading file /home/test/ftplogs/archive/test/ftp.log
Use of uninitialized value in string eq at ./test.pl line 109, <FILE> line 1.

Here is the single entry in the ftp.log file:
Mon Oct 2 11:20:10 2006 23 192.168.0.1 87269520 /xyz2_00HR_ASD_70804_1_86GB_3ABC/1_SPACE IN_FILE_PATH/70804123401.45210221.865760.tar b _ o r janedoe ftp 0 * c
This is the same line of data Paul tested with.
Running this code:
Code:
#!/usr/bin/perl -w
$str="Mon Oct  2 11:20:10 2006 23 192.168.0.1 87269520 /xyz2_00HR_ASD_70804_1_86GB_3ABC/1_SPACE IN_FILE_PATH/70804123401.45210221.865760.tar b _ o r janedoe ftp 0 * c";
#the business end
@temp=split (/\s+/, $str);
my @data = (splice(@temp, 0, 8), undef, splice(@temp, -9));
$data[8] = join(" ",@temp);
#print results
$loop=0;
foreach (@data) {
  print $loop."==> $data[$loop]\n";
  $loop++;
}
Works with this output:
Code:
0==> Mon
1==> Oct
2==> 2
3==> 11:20:10
4==> 2006
5==> 23
6==> 192.168.0.1
7==> 87269520
8==> /xyz2_00HR_ASD_70804_1_86GB_3ABC/1_SPACE IN_FILE_PATH/70804123401.45210221.865760.tar
9==> b
10==> _
11==> o
12==> r
13==> janedoe
14==> ftp
15==> 0
16==> *
17==> c

Is there something I, or we are missing?

Thanks,
Icky
 
I think what you are missing is some of the lines of data being parsed in the ftp logs are not the same as the sample lines of data you posted. Any difference in the real data and the sample data will cause problems.
 
No, no, as I said I AM using the samples as the data to test. Anyways I figured out the problem. I pasted your code:
Code:
 while (<FILE>) {
                chomp;
                my @temp = split(/\s+/);
                my @data = (splice(@temp, 0, 7), undef, splice(@temp, -9));
                $data[8] = join(' ',@temp);
                my ($dow, $month, $day, $time, $year, $duration,
                    $clientip, $size, $path, $ttype, $specialact, $type,
                    $mode, $uid, $service, $authm, $authu, $status) = @data;

Should be:
Code:
while (<FILE>) {
                chomp;
                my @temp = split(/\s+/);
                my @data = (splice(@temp, 0, [COLOR=red]8[/color]), undef, splice(@temp, -9));
                $data[8] = join(' ',@temp);
                my ($dow, $month, $day, $time, $year, $duration,
                    $clientip, $size, $path, $ttype, $specialact, $type,
                    $mode, $uid, $service, $authm, $authu, $status) = @data;

Thanks for the help all involved. I really appreciate it.

Icky
smiletiniest.gif


Stars for Kevin and Paul!
 
Cheers

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top