Quote:
Originally Posted by 123raajesh
1) How can I update the result in destination file itself(rspfile).
|
Inside the awk program you can redirect the output of the print statements to FILENAME, which is an internal variable containing the name of the file that awk is processing:
Code:
...
if ( $1 in _ )
print $1, _[$1] > FILENAME
else
print "#" $0 > FILENAME
...
However this doesn't work for long input files (I don't know what is the limit, anyway). In that case you have to redirect the output to a new file and then rename it as the original input file.
Quote:
2) Could it be possible to restrict to update the rspfile, if the file is already updated with values = $2.
|
Yes. You have to add a further condition, that is if the second field is not empty, then update the value, otherwise print the line without modification (see the part added in red)
Code:
...
if ( $1 in _ )
if ( ! $2 )
print $1, _[$1]
else
print
else
print "#" $0
...
Finally to learn awk I suggest the official
GNU Awk User's Guide, where the first 11 chapters are the basics, the rest is somewhat for advanced users.