bug-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Bug in awk


From: Andrew J. Schorr
Subject: Re: Bug in awk
Date: Thu, 24 Aug 2006 17:25:47 -0400
User-agent: Mutt/1.4.2.1i

On Thu, Aug 24, 2006 at 03:45:44PM +0530, address@hidden wrote:
> Hi,
> Please see the attached text file. It has 5 fields delimited by commas.
> 
> The following command 
>  awk ' BEGIN { FS="," } {a=index($4,"e"); printf 
> "%s\n",substr($4,a-13,a+13) } ' active.txt 
> should give me an output like shown below
> 
> 8TM22N30OGK1QeAV717RFPJG1BG
> BLG2MAHEFE0T0eBNV9FGBMUTQK9
> C5FI84N0NAVACe5ASR0FJBRI70I
> B3L18INGH1743e1OOPIPKIOJVSE
> FVK6PJM0546E4eAD211EO7BC8KE
> 
> but it gives output like this with ~GM~M2 in addition to what is expected
> 
> 8TM22N30OGK1QeAV717RFPJG1BG~GM~M2
> BLG2MAHEFE0T0eBNV9FGBMUTQK9~GM~M2
> C5FI84N0NAVACe5ASR0FJBRI70I~GM~M2
> B3L18INGH1743e1OOPIPKIOJVSE~GM~M2
> FVK6PJM0546E4eAD211EO7BC8KE~GM~M2
> 
> Please let us know why ?? 
> NOTE : We are working on Linux 2.4.21-138-8SP3

Because 'a' evaluates to 40, so you are
printing substr($4,27,53).  The 3rd argument
to substr is the length to print, so it prints
out 53 characters starting at position 27 (which
runs off the end of the string).  Perhaps
what you really want is substr($4,a-13,27)?

Regards,
Andy




reply via email to

[Prev in Thread] Current Thread [Next in Thread]