awk

how can I have awk to print me whole line excluding $1

echo 1 2 3 4 5 | awk .....

2 3 4 5
alexus [ Mo, 21 April 2008 03:04 ] [ ID #1946464 ]

Re: awk

On 2008-04-21, alexus <alexus [at] gmail.com> wrote:
>
>
> how can I have awk to print me whole line excluding $1
>
> echo 1 2 3 4 5 | awk .....
>
> 2 3 4 5
A simple obvious way is awk '{$1="";print}'
Bill Marcum [ Mo, 21 April 2008 03:44 ] [ ID #1946465 ]

Re: awk

On 4/20/2008 8:04 PM, alexus wrote:
> how can I have awk to print me whole line excluding $1
>
> echo 1 2 3 4 5 | awk .....
>
> 2 3 4 5

I'd use "cut" instead:

$ echo 1 2 3 4 5 | awk '{sub(/[^ ]* */,"")}1'
2 3 4 5
$ echo 1 2 3 4 5 | sed 's/[^ ]* *//'
2 3 4 5
$ echo 1 2 3 4 5 | cut -d' ' -f2-
2 3 4 5

Ed.
Ed Morton [ Mo, 21 April 2008 04:22 ] [ ID #1946467 ]

Re: awk

2008-04-20, 21:22(-05), Ed Morton:
> On 4/20/2008 8:04 PM, alexus wrote:
>> how can I have awk to print me whole line excluding $1
>>
>> echo 1 2 3 4 5 | awk .....
>>
>> 2 3 4 5
>
> I'd use "cut" instead:
>
> $ echo 1 2 3 4 5 | awk '{sub(/[^ ]* */,"")}1'
> 2 3 4 5

But:

$ echo " 1 2 3 4 5" | awk '{sub(/[^ ]* */,"")}1'
1 2 3 4 5

You may want:

echo " 1 2 3 4 5" | awk '{sub(/[^ ]+ */,"")}1'
or
echo " 1 2 3 4 5" | awk '{sub(/ *[^ ]+ */,"")}1'

> $ echo 1 2 3 4 5 | sed 's/[^ ]* *//'

sed's equivalent of awk's + is \{1,\}.

echo " 1 2 3 4 5" | sed 's/[^ ]\{1,\} *//'

> 2 3 4 5
> $ echo 1 2 3 4 5 | cut -d' ' -f2-
> 2 3 4 5
[...]

The problem with cut is that it has a different definition of
"field" from awk's one.

--
Stéphane
Stephane CHAZELAS [ Mo, 21 April 2008 13:17 ] [ ID #1946484 ]

Re: awk

On Apr 20, 9:04=A0pm, alexus <ale... [at] gmail.com> wrote:
> how can I have awk to print me whole line excluding $1
>
> echo 1 2 3 4 5 | awk .....
>
> 2 3 4 5

thank you guys!
alexus [ Mo, 21 April 2008 18:32 ] [ ID #1946491 ]

Re: awk

On 2008-04-21, alexus <alexus [at] gmail.com> wrote:
> how can I have awk to print me whole line excluding $1
>
> echo 1 2 3 4 5 | awk .....
>
> 2 3 4 5

awk is the wrong tool. cut is the correct tool, being
fully capable of the task and much more lightweight
than awk.

$ echo 1 2 3 4 5 | cut -d" " -f 2-
2 3 4 5
$

--
Christopher Mattern

NOTICE
Thank you for noticing this new notice
Your noticing it has been noted
And will be reported to the authorities
Chris Mattern [ Mi, 23 April 2008 00:14 ] [ ID #1948225 ]
Linux » comp.unix.shell » awk

Vorheriges Thema: Reading from a file
Nächstes Thema: printf "hi\000"|egrep hi #why no STDERR output