Operating System - HP-UX
1821051 Members
2434 Online
109631 Solutions
New Discussion юеВ

awk '{ print $9 until the end of the line...}'

 
SOLVED
Go to solution
Bill McNAMARA_1
Honored Contributor

awk '{ print $9 until the end of the line...}'

if you do an
ll /
for example and want to awk for the filename,
if that file name is a link there'll be a -> link in the filename
at least the one I want to extract..

how do I specify, from $9 to the end of the line using awk..

Thanks.
Bill

It works for me (tm)
12 REPLIES 12
harry d brown jr
Honored Contributor

Re: awk '{ print $9 until the end of the line...}'

Loop until you get to NF.

live free or die
harry
Live Free or Die
David Lodge
Trusted Contributor

Re: awk '{ print $9 until the end of the line...}'

ll | awk '{ for (i=$9; i <= NF; i++) print $i }'

You are getting lazy with your awk :-)

dave
James R. Ferguson
Acclaimed Contributor

Re: awk '{ print $9 until the end of the line...}'

Hi Bill:

# ... awk '{print substr($9,index($0,$9))}'

...JRF...
Robin Wakefield
Honored Contributor
Solution

Re: awk '{ print $9 until the end of the line...}'

Hi Bill,

ll | awk '{a="";for (i=9;i<=NF;i++){a=a" "$i}print a}'

or less elegantly:

ll | awk '{for (i=1;i<=8;i++){$i=""};print}'

Rgds, Robin.
harry d brown jr
Honored Contributor

Re: awk '{ print $9 until the end of the line...}'

for (i = 9; i < NF; ++i) print $i

Live Free or Die
Deepak Extross
Honored Contributor

Re: awk '{ print $9 until the end of the line...}'

If you'r not very particular about using awk, how about
#ll | tr -s " " | cut -d' ' -f9-
Robin Wakefield
Honored Contributor

Re: awk '{ print $9 until the end of the line...}'

Hi Bill,

One more thing, to ignore the 1st line, start the awk with:

awk 'NR>1{...

The index version will not work exactly if the filename is, say, rw (which mine often are!), since it will pick up the "rw" in the permissions.

Rgds, Robin.
Bill McNAMARA_1
Honored Contributor

Re: awk '{ print $9 until the end of the line...}'

I'll give points tomorrow, I keep getting 404's

Have a great day!

Thanks,
Bill
It works for me (tm)
Deepak Extross
Honored Contributor

Re: awk '{ print $9 until the end of the line...}'

You may want to skip the first line in the output of ll:
ll | tr -s " " | cut -d" " -f9- | tail +2
Deepak Extross
Honored Contributor

Re: awk '{ print $9 until the end of the line...}'

Bill,
Did you report your 404s to Dan's thread on forum Issues?
I believe he uses the info to generate some mothly reports or such.
James R. Ferguson
Acclaimed Contributor

Re: awk '{ print $9 until the end of the line...}'

Hi Robin (and Bill):

Great, ironic (?) catch, Robin. I flat missed the match that would occur. What's more, I even bungled the brain to fingers connection, meaning to have written:

...awk '{print substr($0,index($0,$9))}'

In any event, the "shortcut" I suggested clearly has deficiencies. Thanks for catching it!

Regards!

...JRF...
Bill McNAMARA_1
Honored Contributor

Re: awk '{ print $9 until the end of the line...}'

yea, I reported the 404's.

Thanks all.
Later,
Bill
It works for me (tm)