Another.Chemist
Another.Chemist

Reputation: 2559

BASH: How to replace a value in a matrix?

I have a matrix of mxn. I want to replace the pattern1 with a word and that pattern is at row 3, column 4.

How can I do that?

So far... I know how to acces to the value at row 3 and column 4:

awk 'NR==3' $1 | awk -vvar="4" '{print $var}'

But ... how can I replace that pattern located at that cell?

Upvotes: 0

Views: 140

Answers (1)

PesaThe
PesaThe

Reputation: 7499

awk 'NR==3{ sub("pattern", "replacement", $4) } 1' "$1"
  • sub: one of the substitution functions. See manual for more information
  • 1: idiomatic way of saying { print $0 }

Upvotes: 1

Related Questions