unix - awk script not working properly in SunOS (which worked well with Red Hat) -
i looking out file replacement functionality done in awk
. had solution worked red hat linux flavour not working sunos 5.10. great if can troubleshoot issue.
source file (src.txt)
aaaa uid=xxxx pwd=nnnn u_no=12345 bbbb uid=yyyy pwd=eeee zzzz uid=yyyy pwd=eeee
reference file (ref.txt)
block,parameter,value aaaa,uid,1a1a aaaa,pwd,1b1b bbbb,uid,2a2a zzzz,pwd,9b9b zzzz,uid,9a9a bbbb,pwd,2b2b
required output file (tgt.txt)
the target file should updated source file based on lookup values reference file follows:
aaaa uid=1a1a pwd=1b1b u_no=12345 bbbb uid=2a2a pwd=2b2b zzzz uid=9a9a pwd=9b9b
code
awk -f= ' fnr==nr { split($0,b,",") a[b[1] fs b[2]]=b[3] next} !/=/ { f=$1 print next} { print $1"="(a[f fs $1]?a[f fs $1]:$2)} ' ref.txt src.txt > tgt.txt
the code solution given 1 of our friends here in stack overflow , worked pretty in red hat linux.
when tried copy sunos 5.10, first showed syntax error at:
!/=/ {
i replaced field separator value , stopped showing syntax error.
ofs="="
for this, script executes, prints source file values (not updated value).
can me find solution this?
use nawk
(new awk) or /usr/xpg4/bin/awk
(posix awk) solaris. awk
original legacy version.
here works:
nawk -f= ' fnr==nr { split($0,b,",") a[b[1] fs b[2]]=b[3] next} $0 !~ "=" { f=$1 print next} { print $1"="(a[f fs $1]?a[f fs $1]:$2)} ' ref.txt src.txt > tgt1.txt
Comments
Post a Comment