Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

All fields after $4

Status
Not open for further replies.

columb

IS-IT--Management
Feb 5, 2004
1,231
EU
This should be simple but I can't find it in the O'Reilly book.
What I want to do is the equivalent of
Code:
cut -d ' ' -f 7-
OK, the -d ' ' bit is easy (and the default) but how do I get every field after the 7th?

Thanks

Ceci n'est pas une signature
Columb Healy
 
Er, excuse the inconsistancy between the heading and the 'cut' statement. It's the principle I'm after.

Thanks

Ceci n'est pas une signature
Columb Healy
 
What you posted seems to work fine for me on Linux and Solaris, what operating system exactly?

[tt]$ echo one two three four five six | cut -d ' ' -f 3-
three four five six
$[/tt]

Annihilannic.
 
Sorry, I need the awk equivalent. What I have a the moment is something along the lines of
Code:
ls -l | grep wantedfile | cut -d ' ' -f 6-
What I want is
Code:
ls -l | awk '/wantedfile/ {print ????}'
Apart from wishing to increase my awk knowlege whenever I see a grep with something else it always say to me that awk ought to be able to do it better.

Ceci n'est pas une signature
Columb Healy
 
You want the awk equivalent? Off-hand, something like

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

I would think for 5th field and beyond.

I believe cut is rather pecky about the field separator - tab not space is the default, and multiple field separators mean that there's an empty field in between. (not so for awk).


HTH,

p5wizard
 
Unfortunately it's not exactly brief:

[tt]ls -l | awk '/wantedfile/ {for (i=6;i<=NF;i++) {t=t $i OFS};print t}'[/tt]

Annihilannic.
 
Thanks p5wizard and Annihilannic. I was hoping to do it without the loop but you've confirmed that I can't.

Ceci n'est pas une signature
Columb Healy
 
a dirty way without a loop if it's just a couple of fields:

awk '{$1=$2=$3=$4="";print}'

but the field separators get left behind.

HTH,

p5wizard
 
shift left by 4 fields
Code:
nawk '{$1=$2=$3=$4="";sub("^" FS "*","")}1' shift.txt

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top