LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Parsing rync output for progress bar in dialog (http://www.linuxquestions.org/questions/programming-9/parsing-rync-output-for-progress-bar-in-dialog-4175423107/)

yamanoorsai 08-20-2012 03:52 PM

Parsing rync output for progress bar in dialog
 
I am trying to display a progress bar in dialog using the output of rsync command. I found this answer while doing my search. The answer is useful only if you are transferring a large number of uncompressed files. I am trying to transfer a single large compressed file. I tried the following:

Code:

rsync -a --progress test.tar.gz /media/sdb1 > test.txt
My output looks like this:

Code:

32768  0%    0.00kB/s    0:00:00 
80510976  2%  76.75MB/s    0:00:48

I need the percentage data from the second column. Is there a way to print only 1 line of data at a time? Is there a better way of parsing the output of rsync command to obtain the percentage of progress?

byannoni 08-20-2012 09:53 PM

Try this:
Code:

rsync -a --progress test.tar.gz /media/sdb1 | awk '{printf "\r%s", $2}'

yamanoorsai 08-21-2012 10:39 AM

I tried your suggestion. The values being printed are:

Code:

file

0%

bytes

This is being printed after the script has executed. I need to turn off the buffer. I am still not able to print the percentage data

yamanoorsai 08-21-2012 05:12 PM

I figured it out. I did it as follows:

Code:

rsync -a --progress data-000.tar.gz /media/PENDRIVE | unbuffer -p grep -o "[0-9]*%" | tr -d '%'


All times are GMT -5. The time now is 03:12 PM.