You are not logged in.
Pages: 1
Hello,
I'd like for some reason reformat the output from one program to mine.
Some is a still repeating line, such as mplayer. (They overwrite on the same line)
My vane efforts are trying to extract the percentage from those lines, but fifo or pipe don't get that line. Perhaps because it's expected lines ended by a newline.
Beside that, my trials with expr or sed going no where. I'm puzzled to find the world which has % leading sign and 2 or 3 digits before the decimal point and 1 or 2 digits after the decimal point like $$.$$% or $$.$%.
I've read many manuals of sed, bash, regex but seems that some regex doesn't do what I would like to be done.
So, what would be a simple extraction with small programs like sed, grep, awk or bash itself?
do it good first, it will be faster than do it twice the saint
Online
Perhaps because it's expected lines ended by a newline.
That’s your main problem. Try replacing \r with \n:
mplayer foo.avi | tr '\r' '\n' | sed ...
Offline
If there are no newlines, you have to read it byte by byte:
a=0
{ while sleep 0.5
do echo -n $((a+=1))
((a==4))&&break
done } | while read -n 1; do
[[ $REPLY == 3 ]] && echo -n 5 || echo -n $REPLY
done
Offline
Try replacing \r with \n:
That's a great idea. it will probably get the output into a (named) pipe and catch the last line with tail -n1
==================================================================
EDIT
That's wouldn't work, because even tr won't get the output, for the exact reason that isn't "\n" terminated.
It took me some long thinking
==================================================================
More research of mine I could get what I need, by use of awk
$ a='xfe43.6%gege 96% vvbf yyy' # A sample string for test.
echo $a | awk '{for (i=1; i <=NF; i++) {if ($i ~ /([0-9]*%$)/) print $i}}'
# result ==> 96%
In human thinking it means 'read all fields and if one of them contain % print it out'. I don't know (yet) a more accurate regex to avoid false positive results.
For one line reading I can get the figure and I may use it on zenity to display a progress bar
Last edited by TheSaint (2012-09-11 10:44:48)
do it good first, it will be faster than do it twice the saint
Online
Check out stdbuf for running commands with different buffering operations.
Offline
Vain wrote:Try replacing \r with \n:
That's a great idea. it will probably get the output into a (named) pipe and catch the last line with tail -n1
==================================================================
EDIT
That's wouldn't work
Well, yes, it works. But it may appear not to work right now due to buffering issues. See quigybo’s comment and have a look at stdbuf.
Offline
Thanks to enlight me. It was something I just read but I didn't find a solution to reduce the buffer size, like this.
I found mentioning that normal buffering is 4 Kb as standard size. Each pipe would add a new buffer, therefore the delay would grow proportionally.
Another of mine trial was to catch the aria2c output, but I'm bit confuse. would it be some as stdbuf -o 80 aria2c | myscript ?
Should I use to flush the stdin?
Last edited by TheSaint (2012-09-12 14:17:22)
do it good first, it will be faster than do it twice the saint
Online
Pages: 1