awk

awk

am 21.04.2008 03:04:27 von alexus

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

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

2 3 4 5

Re: awk

am 21.04.2008 03:44:34 von Bill Marcum

On 2008-04-21, 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
A simple obvious way is awk '{$1="";print}'

Re: awk

am 21.04.2008 04:22:22 von 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
$ 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.

Re: awk

am 21.04.2008 13:17:20 von Stephane CHAZELAS

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

Re: awk

am 21.04.2008 18:32:46 von alexus

On Apr 20, 9:04=A0pm, 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

thank you guys!

Re: awk

am 23.04.2008 00:14:54 von Chris Mattern

On 2008-04-21, 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

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