|The stupid question is the question not asked|
parse a line with varied number of fieldsby raggmopp (Novice)
|on Jul 03, 2012 at 03:27 UTC||Need Help??|
raggmopp has asked for the
wisdom of the Perl Monks concerning the following question:
Working with perl 5.8.8 on RHEL 5.x. An ftp server using vsftp. I want to get the file name but the file name could include spaces, thus there could be a varied number of fields per line.
The file name, with it's PATH, begins at the 9th field of a line. The last 9 fields are the same as they pertain to the ftp process. So I am thinking on dropping the 1st 8 fields and the last 9 fields.
If there are no spaces in the file name, there will be 18 fields on a line. If there is a space, or spaces, in a file name then there will be 19, or more, fields on a line.
But the file name will always start at the 9th field and the last 9 fields can be dropped. What is in the middle, 1 field, 2 fields, 3 fields, ... will be the file name.
I can identify the lines I need, but when I see a space in a file name, or spaces, it kinda halts my thought.
The code I've put together. I am testing for incoming and a pattern match, 1 of 4 possibilities.
From these lines that have been identified, cut '$fields...$fields7' and cut '$fields$NF...$fields-8'. So what is left is the file name with it's PATH and any spaces if spaces exist in the file name.