Home > Archive > AWK > May 2004 > Printing the last column in a record
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Printing the last column in a record
|
|
| Dave Rudolf 2004-05-17, 11:31 am |
| Hi all,
Just a curiosity of mine. I was wondering if it is possible to print the
last "column" in each "record", but where each record can have an arbitrary
number of columns. For example, if I did something like
find . | awk '{ ...something... }'
and I just wanted the names of the files, with the path prefix removed. Any
idea on how to do this in awk (or any other standard unix program, for that
matter)?
Dave
| |
| Ed Morton 2004-05-17, 12:30 pm |
|
Dave Rudolf wrote:
> Hi all,
>
> Just a curiosity of mine. I was wondering if it is possible to print the
> last "column" in each "record", but where each record can have an arbitrary
> number of columns. For example, if I did something like
>
> find . | awk '{ ...something... }'
>
> and I just wanted the names of the files, with the path prefix removed. Any
> idea on how to do this in awk (or any other standard unix program, for that
> matter)?
>
> Dave
>
>
awk -F'/' '{print $NF}'
Ed.
| |
| Frank 2004-05-19, 12:30 am |
| >> and I just wanted the names of the files, with the path prefix
removed.Any
that[color=darkred]
>
> awk -F'/' '{print $NF}'
>
Okay. What is the best way to go about breaking up the current filename
internally within an AWK script? I'm currently using FILENAME which is
currently giving me the fully pathed filename (minus the drive letter). My
current solution is to call the "split" function using "." (to remove the
extension) and then to call it again with "\\" (to get the various pieces).
Then I have to loop through the second array until I find the last element.
I'm sure there is a simpler way. Anyone have any suggestions?
| |
|
| assuming there is an extension:
fileLessExt=y[split(z[split(FILENAME,z,"\\")],y,".")-1]
--
pop is Mark
I'm lost. I've gone to look for myself.
If I should return before I get back, keep me here.
--
"Frank" <fmankal@rogers.com> wrote in message
news:jGAqc.29802$Zxc.9597@news04.bloor.is.net.cable.rogers.com...
> removed.Any
> that
>
> Okay. What is the best way to go about breaking up the current filename
> internally within an AWK script? I'm currently using FILENAME which is
> currently giving me the fully pathed filename (minus the drive letter). My
> current solution is to call the "split" function using "." (to remove the
> extension) and then to call it again with "\\" (to get the various pieces).
> Then I have to loop through the second array until I find the last element.
> I'm sure there is a simpler way. Anyone have any suggestions?
>
>
| |
| nameless@noname.net 2004-05-22, 4:30 pm |
| To print the last colum of the input use print $NF
Built in variable NF is the number of fields on the current row
|
|
|
|
|