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
|
|
|
| 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.
|
|
|
|
|