Created
July 4, 2017 22:41
-
-
Save mrrusof/f252d8633fd6257777d620b66326c0d4 to your computer and use it in GitHub Desktop.
In Bash, given a matrix, return element in given row & col
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| function element { r=$1; c=$2; head -n $r | tail -n 1 | awk "{ print \$$c }"; } | |
| # Example usage: | |
| # | |
| # $ echo -e "1 2 3\n4 5 6\n7 8 9" | element 2 2 | |
| # 5 | |
| # $ echo -e "1 2 3\n4 5 6\n7 8 9" | element 2 3 | |
| # 6 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment