On 5/5/2008 8:56 AM, Kenny McCormack wrote:
> In article <481F09BE.9030703@[EMAIL PROTECTED]
>,
> Ed Morton <morton@[EMAIL PROTECTED]
> wrote:
>
>>On 5/5/2008 3:58 AM, Nezhate wrote:
>>
>>>Thanks for your help.
>>>I have another question:
>>>how to delete en entire specified lines in file using awk
>>>, for example I want to delete the 5 th, 8 and 10 th line in file2 ?
>>
>>awk 'BEGIN{split("5 8 10",t);for(i in t)skip[t[i]]} !(NR in skip)' file
>>
>> Ed.
>>
>
>
> I was thinking along those lines, but it does seem a little bulky,
I agree. This comes up frequently so I do wish there was a utility
function like
"split()" that populated the resultant array with the string segments as
indices
rather than entries indexed by the order they appear in the string.
> not to mention that someone might point out that array lookups might be
> costly (not that any of us is likely to ever notice it in our
lifetimes).
>
> How about: NR ~ /^(5|8|10)$/
>
> Note that since this is a static RE, it will be compiled at compiletime,
> not at runtime, so it should be pretty efficient.
>
Nice!
Ed.


|