Hello hello -- never used AWK before, but I hear it's a mighty fine search and replace tool.
Here's my issue: I would like to replace every line that contains "prevBoard[x][y][z]" with "MYINDEX3D(prevBoard, n, n2, x, y, z)", where x, y, and z represent variable text of max length 3.
I have written the following AWK script:
However, I want to tell AWK that x, y, and z are variables. I don't want it thinking that x, y, and z are literally written into the code. How would I go about doing that?
Thanks in advance.
Edit: Also, how to tell AWK to run this on a certain file? Right now this is saved as "f_and_r.sh" -- would I do something like ./f_and_r.sh filename.txt ?
Edit2: Looks like I can do: awk -f f_and_r.sh filename.txt. Guess I'll just pipe that output into a new text file or something.
Here's my issue: I would like to replace every line that contains "prevBoard[x][y][z]" with "MYINDEX3D(prevBoard, n, n2, x, y, z)", where x, y, and z represent variable text of max length 3.
I have written the following AWK script:
Code:
awk '\
{
sub(/prevBoard[x][y][z]/, "MYINDEX3D(prevBoard, n, n2, x, y, z)");
print
}'
However, I want to tell AWK that x, y, and z are variables. I don't want it thinking that x, y, and z are literally written into the code. How would I go about doing that?
Thanks in advance.
Edit: Also, how to tell AWK to run this on a certain file? Right now this is saved as "f_and_r.sh" -- would I do something like ./f_and_r.sh filename.txt ?
Edit2: Looks like I can do: awk -f f_and_r.sh filename.txt. Guess I'll just pipe that output into a new text file or something.