For Programmers: Free Programming Magazines  


Home > Archive > AWK > February 2008 > AWK & FIXED WIDTH FILE to REPLACE VALUE









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author AWK & FIXED WIDTH FILE to REPLACE VALUE
Kels

2008-02-11, 6:58 pm

I have limited knowledge of UNIX and a fixed witdth file of over 4
million records. I need to match a pattern at a specific location in
each record and replace the value. The following is an example of the
awk I would use to find my pattern

=83=DE awk 'substr($0,153,8)=3D=3D"94695577"'

How can I use this to replace the value.
Ed Morton

2008-02-11, 6:58 pm

On 2/11/2008 1:21 PM, Kels wrote:
> I have limited knowledge of UNIX and a fixed witdth file of over 4
> million records. I need to match a pattern at a specific location in
> each record and replace the value. The following is an example of the
> awk I would use to find my pattern
>
> ? awk 'substr($0,153,8)=="94695577"'
>
> How can I use this to replace the value.

awk 'substr($0,153,8)=="94695577"{$0=substr($0,1,152)"rep"substr($0,160)}1' file

or with GNU awk:

awk --re-interval '{print gensub(/(.{152})94695577/,"\\1rep","")}' file

Regards,

Ed.

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com