I would like the option of extracting the following string/data:
/work/foo/processed/25
/work/foo/processed/myproxy
/work/foo/processed/sample
=or=
25
myproxy
sample
But it would help if I see both.
From this output using cut
or perl or anything else that would work:
Found 3 items
drwxr-xr-x - foo_hd foo_users 0 2011-03-16 18:46 /work/foo/processed/25
drwxr-xr-x - foo_hd foo_users 0 2011-04-05 07:10 /work/foo/processed/myproxy
drwxr-x--- - foo_hd testcont 0 2011-04-08 07:19 /work/foo/processed/sample
Doing a cut -d" " -f6
will get me foo_users
, testcont
. I tried increasing the field to higher values and I'm just not able to get what I want.
I'm not sure if cut
is good for this or something like perl?
The base directories will remain static /work/foo/processed
.
Also, I need the first line Found Xn items
removed. Thanks.
You can do a substitution from beginning to the first occurrence of
/
, (non greedily)Or you can find a unique separator (field delimiter) to split on. for example, the time portion is unique , so you can split on that and get the last element. (2nd element)
With awk,
take the output of your ls command and pipe it to awk
Try this out :
In this example, the last word in the input will be matched . (The word can also contain dot(s)),so file names like 'text_file1.txt', can be matched). Ofcourse, you can change the pattern, as per your requirement.
Here is an explanation of the command-line switches used:
If you want to just output the last portion of your directory path, and the basedir is always '/work/foo/processed', I would do this:
If you know the columns will be the same, and you always list the full path name, you could try something like:
which would cut out the 79th character until the end. That might work in this exact case, but I think it would be better to find the basename of the last field. You could easily do this in awk or perl. Respond if this is not what you want and I'll add the awk and perl versions.