Re: how to grep "[0]" file?

From: Chris F.A. Johnson (cfajohnson_at_gmail.com)
Date: 11/03/04


Date: 3 Nov 2004 05:29:18 GMT

On 2004-11-03, baumann.Pan@gmail.com wrote:
> in a file contains lots statement below
>
> getproc_got_int32(pktp, vbp,
> data->sEXPAND_FRAME_STATUS[0].eaFXS_STATUS[0]); /* !!! */
>
>
> how can I grep [0]); and replace it with
> [1]); in the first match,
> [2]); in the 2nd math , and so on?

   If you want multiple instances on the same line to be incremented:

awk '{ while ( sub( "\\[0\\]", "[" n + 1 "]" )) ++n ; print}' FILE

   If you want all instances on the same line to have the same number:

awk '{ if ( gsub( "\\[0\\]", "[" n + 1 "]" )) ++n ; print}' FILE

   If you want all instances on the same line to have the same number,
   yet increment the number by the number of occurrences:

awk '{ if ( n += gsub( "\\[0\\]", "[" n + 1 "]" )) ; print}' FILE

-- 
    Chris F.A. Johnson                  http://cfaj.freeshell.org/shell
    ===================================================================
    My code (if any) in this post is copyright 2004, Chris F.A. Johnson
    and may be copied under the terms of the GNU General Public License