Hey guys, "new" to perl and working on first script to parse some verbose output to csv lines. Thought I had it working until I realized that there was a couple of lines in the input that were formatted different. Long story short, In the input file "$path" is usually the first instance of "/ifs/*", but I found that in some cases if the path name was considered to long by the OS command... it truncated the line with "..." and reported the full pathname in one line below the normal field location i.e.:
Type Path Policy Snap +Usage -------------------- ------------------------------ ----------- ----- +-------- directory /ifs/home/admin enforcement no + 32K [hard-threshold] ( 1.0G) [hard-threshold-exceeded] (no) [container] [usage-with-no-overhead] ( 32K) [usage-with-overhead] ( 103K) [usage-inode-count] (4) directory /ifs/home/ftp enforcement no + 31B [hard-threshold] ( 1.0G) [hard-threshold-exceeded] (no) [container] [usage-with-no-overhead] ( 31B) [usage-with-overhead] ( 6.0K) [usage-inode-count] (3) directory /ifs/gpd/data/trufusion/dat... enforcement no + 43G /ifs/gpd/data/trufusion/data0003 [hard-threshold] ( 80G) [hard-threshold-exceeded] (no) [container] [usage-with-no-overhead] ( 43G) [usage-with-overhead] ( 95G) [usage-inode-count] (606)
Figured I have to use a if/else statement checking for the presence of "..." and perform one or two actions (based of input formatting to grab the full "path" word. Here is what I have so far. I commented out the else line temp until I can figure out why the "if" is always false regardless of what I try:
#!/usr/bin/perl -w my $filename = "quotas.txt"; open FILE, "$filename" or die "Cannot open $filename for reading: $!\n +"; open REPORT, ">report.csv" or die "Cannot open report.csv for writing: + $!\n"; undef $/; my $file = <FILE>; $/ = "\n"; my ($header,@records) = split /directory\s+/, $file; while (@records){ my $line = shift @records; if ($line !~ /\.\.\./) { my ($path, $usage, $threshold) = $line =~ / (\S+) #grab path \D+ (\d\S+) #stop at the first digit for usage .*? \[hard-threshold\] #seek out threshold .*? \(\s+(.*?)\) #capture threshold inside parens /sx; print REPORT "$path,$usage,$threshold\n"; } print $line # else { # my ($usage, $path, $threshold) = $line =~ / \S+ #grab path # \D+ # (\d\S+) #stop at the first digit for usage # .*? # (\S+) # \[hard-threshold\] #seek out threshold # .*? # \(\s+(.*?)\) #capture threshold inside parens # /sx; # print "$path,$usage,$threshold\n"; # } }
Can someone please put me on the right path on how to check if "$line" contains text pattern "..." for my if statement??? Thanks!!!
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |