in reply to read the filename column
Assuming that the 'username', 'BatchID', 'size', 'Date', 'Status' and 'Owner' fields will never have embedded whitespace, then this is perhaps not more 'efficient', but I think more maintainable:
>perl -wMstrict -le "my $rec = 'user2 1707 amanda test 1 .doc.412 4064 ' . '11/07/08-15:47 CREMFY roadtest' ; print qq{'$rec'}; ;; my ($username, $batchid, $remainder) = split /\s+/, $rec, 3; my $filename = reverse((split /\s+/, reverse($remainder), 5)[-1]); ;; print qq{'$username' '$batchid' '$filename'}; " 'user2 1707 amanda test 1 .doc.412 4064 11/07/08-15:47 CREMFY + roadtest' 'user2' '1707' 'amanda test 1 .doc.412'
Update: Something like this approach would work well if the data fields are variable-width; if they are fixed-width as the example data of the OP suggest, the unpack approach of Re: read the filename column would be far better.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: read the filename column
by roadtest (Sexton) on Jul 09, 2011 at 17:48 UTC |