Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

BASH Please refactor this code to be more efficient. Thanks! if [ $1 -eq $column

ID: 3911415 • Letter: B

Question

BASH

Please refactor this code to be more efficient. Thanks!

if [ $1 -eq $column then if [ $fileExist -ne 1 ] #check if temp file exists then fileExist-1 if I $x -eq $columnt then echo $sum > $tempo4 #if the space should be a value #then print the value to the file else printf "%s " $sum > $tempo4 #else place a TAB in the file Fi else #since the file is already there, we will append from now on if I $x -eq $columnt then echo $sum >> $tempo4 #putting a data value in the file else printf "%s " $sum >> $tempo4 #placing a tab fi fi fi

Explanation / Answer

if [$1 -eq $column]

then

if[$fileExist -ne 1]

then

fileExist=1

if[$x -eq $columnt]

then

echo $sum >>$tempo4

else

printf "%s " $sum >> tempo4

fi

fi

fi

we can remove first if by using simple appending even in case file does not exist it will create and write. if file exist it will append thus removing unneccesary extra processing