For Programmers: Free Programming Magazines  


Home > Archive > AWK > May 2006 > Re: In awk -- how to 'cat' a file for it's value and update another









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 Re: In awk -- how to 'cat' a file for it's value and update another
Ed Morton

2006-05-17, 6:57 pm

onewayonlytojesus@yahoo.com wrote:
> onewayonlytojesus@yahoo.com wrote:
>
>
>
> I hope I did the 'google' right this time.


Yes!

> One more 'minor question' -- I appreciate the 'awk' single line rather
> than a shell -- I need to do this on some other shells that I have.
> Anyway...I modified the command you gave me, but now I'm not getting my
> field separators only for the TDT line being updated -- every other
> line is correct. I've tried several things with the field separator
> and stuff...but have hit another brick wall.
> Here is the 'schvoy' file:
> 081E
>
> Here is my 'baplie' file:
> UNA:+.?
> UNB+UNOA:2+BAL+ITO+060508:0607+368073+++
++EIS
> UNH+368073-838+BAPLIE:D:95B:UN:SMDG20
> BGM++368073-838+9
> DTM+137:0605080607:201
> TDT+20+0309+++EIS:172:20+++:::SUN ROAD
> LOC+5+USBAL:139:6
> LOC+61+JPNGO:139:6
>
> Here is the awk command:
> awk -F+ -v saved=`cat schvoy` '$1 ~ /TDT/{$3=saved}1' < baplie >
> baplieout
>
> Here is the output of baplieout:
> UNA:+.?
> UNB+UNOA:2+BAL+ITO+060508:0607+368073+++
++EIS
> UNH+368073-838+BAPLIE:D:95B:UN:SMDG20
> BGM++368073-838+9
> DTM+137:0605080607:201
> TDT 20 081E EIS:172:20 :::SUN ROAD
> LOC+5+USBAL:139:6
> LOC+61+JPNGO:139:6
>
>
> I really appreciate the help. I'm new at all of this 'group
> questions'...
> :)
>


You set the input field separator to "+" by using "-F+" but you didn't
set the output field separator so when yopu assign a new value to $3, it
reconstructs $0 using the default output separator, i.e. a blank
character. Try this:

awk -v saved=`cat schvoy` 'BEGIN{FS=OFS="+"}$1 ~ /TDT/{$3=saved}1' <
baplie > baplieout

Regards,

Ed.
Sponsored Links







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

Copyright 2008 codecomments.com