I wanted to be done in awk for a file replacement functionality. I had a solution that worked well for the Red Hat Linux flavor but it is not working well with SunOS 5.10. It would be good that someone can help in troubleshooting this problem.
Source file (src.txt)
aaaa uid = xxxx pwd = NNNN u_no = 12345bbbb uid = yyyy pwd = eeeeZZZZ uid = Yyyy pwd = eeee reference file (ref.txt)
block, parameter, value aaaa, uid, 1a1a Aaaa, pwd, 1b1bbbbb, uid, 2a2azzzz, pwd, 9b9bzzzzz, uid, 9a9abbbb, pwd, 2b2b required output file (tgt.txt) )
The target file should be as file based on the viewing values from an updated source reference file as follows:
aaaa uid = 1a1a pwd = 1b1b u_no = 12345bbbb uid = 2a2a pwd = 2b2bZZZZ uid = 9a9a pwd = 9b9b
code
< Pre> awk -F = 'fnr == nr} partition ($ 0, b, ",") a [b] [1] fsb [2]] = b [3] next}! / = / {F = $ 1 Print Next} {Print $ 1 "=" (A [FFS $ 1]? A [FFS $ 1]: $ 2)} 'Refact. TST src.txt & gt; Tgt.txt The code solution was given by a friend in our stick overflow and it works very well in Red Hat Linux.
When I tried to copy it to SunOS 5.10, it first showed a syntax error:
! / = / { I changed field separator value and stopped displaying this syntax error. For this, executes scripts, but prints only source file values (not an updated value).
>Can you help me find a solution for this?
No comments:
Post a Comment