I have a text file like this:
if I was given string in column 1 and 2 (which are subject 1 and LecturerA) , i need to update 3rd field of that line containing that given string , which is, number 10 need to be updated to 100 ,for example.
The following works:
But if I want to pass sub and lec to another variable from user input , it does not work:
any idea?
Thanks.
Code:
subject1:LecturerA:10
subject2:LecturerA:40
The following works:
Code:
awk -F: '{if($1~sub&&$2~lec){$3=newMark}}1' sub="subject1" lec="LecturerA" newMark=100 OFS=":" test.txt
Code:
sb="subject1"
lect="LecturerA"
mark=100
Code:
awk -F: '{if($1~sub&&$2~lec){$3=newMark}}1' sub=$sb lec=$lect newMark=$mark OFS=":" test.txt
Thanks.