Write Bash Script Add Two Matrix Text File Together Using Read Line Loop Without Using Awk Q37156457

Write a bash script that add two matrix textfile together using read line and for loop, butwithout using awk

m1 : 1 2 3 4 m 2: 1 2 3 4

1 2 3 4 1 2 3 4 Show transcribed image text 1 2 3 4
1 2 3 4


Answer


// text codestarts here

#!/bin/bash

# getting the size of matrix
j=0
i=0

#get number of column
input=”/home/rahul/Desktop/m1.txt”
while IFS= read -r line
do
for num in $line
do
   ((j++))
done
break
done < “$input”

input=”/home/rahul/Desktop/m1.txt”
#get number of rows
while IFS= read -r line
do
((i++))
done < “$input”

#save the row size in variable m and column size in

OR
OR

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.