For Programmers: Free Programming Magazines  


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









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 In awk -- how to 'cat' a file for it's value and update another file
onewayonlytojesus@yahoo.com

2006-05-16, 6:58 pm

I have a file (schvoy) with one variable.
I have a file (baplie) with many lines.
I only want to update the line in file baplie that has $1 ~ /TDT/ and I
want to update $3 with the value of file schvoy.
I feel like I have tried everything.
Please advise the best and easiest way to pass the value in schvoy file
using awk.

Thanks very much.

onewayonlytojesus@yahoo.com

2006-05-16, 6:58 pm

Ed,
Thank you very much. I was trying to 'pass' the `cat schvoy` value in
an awk script. The file name baplie will change each time, but schvoy
will not. Do you mind offering a little more help?
I do appreciate it.
Cindy :)

onewayonlytojesus@yahoo.com

2006-05-17, 6:57 pm


onewayonlytojesus@yahoo.com wrote:
> I have a file (schvoy) with one variable.
> I have a file (baplie) with many lines.
> I only want to update the line in file baplie that has $1 ~ /TDT/ and I
> want to update $3 with the value of file schvoy.
> I feel like I have tried everything.
> Please advise the best and easiest way to pass the value in schvoy file
> using awk.
>
> Thanks very much.


I hope I did the 'google' right this time.
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'...
:)

onewayonlytojesus@yahoo.com

2006-05-17, 6:57 pm


onewayonlytojesus@yahoo.com wrote:
Awesome....just what I was looking for...
>
> Thanks very much.


Sponsored Links







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

Copyright 2008 codecomments.com