I was trying the below script in terminal as well as script file,
while IFS= read -r line; do
line_found=$(echo $line | grep "copied" && b_found=1 || b_found=0)
echo $line_found
str_source_1=$(echo $line_found | cut -d" " -f1)
echo $str_source_1
l_n_bytes_copied=$str_source_1
echo $l_n_bytes_copied
done < progress_log.txt
But is giving the error,
0
8159232 bytes (8.2 MB) copied, 1.000737 s, 8.2 MB/s
8159232
8159232")syntax error: operand expected (error token is "
I am stuck on this error, also tried echo $line_found | awk '{print $1}' to extract the number from the file,
File contains
I need to get the first number of last line in the file,
In the script file,
declare -i l_n_bytes_copied=0;
line_found="";b_found=0;
while read line;
do
line_found=$(echo $line | grep "copied" && b_found=1 || b_found=0);
if [ $b_found == 1 ] | [ "$line_found" != "" ];
then
str_source_1=$(echo $line_found | cut -d" " -f1);
echo "---1 $str_source_1";
l_n_bytes_copied=$str_source_1;
#Another method tried :- Adding these for better understanding what I have done
#l_n_bytes_copied=$(echo $line_found | awk '{print $1}')
# sed is used to replace the ^M as \n, because input file is showing as one line file with seprator ^M file while opening with vim editor, this command has performed earlier before this script made the file as line line by line,
#sed -i -e 's/^M/\n/g' progress_log.txt
fi;
done < p_log.txt ;