LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Urgent Help Needed (http://www.linuxquestions.org/questions/programming-9/urgent-help-needed-696347/)

waqasdaar 01-10-2009 12:29 PM

Urgent Help Needed
 
I just want to print a last line of output of command during its execution time. Is there a way to do this ?

For example

$ ./tt.sh /home/JHON/Videos/Ala_sinistra.avi
FFmpeg version git-5a82e37, Copyright (c) 2000-2008 Fabrice Bellard, et al.
configuration:
libavutil 49.12. 0 / 49.12. 0
libavcodec 52. 3. 0 / 52. 3. 0
libavformat 52.23. 1 / 52.23. 1
libavdevice 52. 1. 0 / 52. 1. 0
built on Nov 17 2008 15:13:29, gcc: 3.3.5 (Debian 1:3.3.5-13)

Seems stream 0 codec frame rate differs from container frame rate: 30000.00 (30000/1) -> 25.00 (25/1)
Input #0, avi, from '/home/waqasdaar/Videos/Ala_sinistra.avi':
Duration: 00:04:07.28, start: 0.000000, bitrate: 754 kb/s
Stream #0.0: Video: mpeg4, yuv420p, 320x240 [PAR 1:1 DAR 4:3], 25.00 tb(r)
Stream #0.1: Audio: mp3, 44100 Hz, stereo, s16, 160 kb/s
File 'temp.m2v' already exists. Overwrite ? [y/N] y
Output #0, mpeg2video, to 'temp.m2v':
Stream #0.0: Video: mpeg2video, yuv420p, 320x240 [PAR 1:1 DAR 4:3], q=2-31, 4000 kb/s, 25.00 tb(c)
Stream mapping:
Stream #0.0 -> #0.0
Press [q] to stop encoding
Compiler did not align stack variables. Libavcodec has been miscompiled
and may be very slow or crash. This is not a bug in libavcodec,
but in the compiler. You may try recompiling using gcc >= 4.2.
Do not report crashes to FFmpeg developers.
frame= 625 fps=103 q=1.6 size= 12151kB time=24.96 bitrate=3988.0kbits

I just want to print the last line which is bold. Can any one help me?

Thanks in Advanced

Sergei Steshenko 01-10-2009 01:07 PM

man tail

repo 01-10-2009 01:14 PM

Please use a title that is relevant to your question.
"Urgent Help Needed" is often ignored.

waqasdaar 01-10-2009 01:23 PM

i have tried a lot with tail as well as sed but i does not work.
any other idea ?

bgeddy 01-10-2009 01:34 PM

Piping output to tail with the option set for tail to output only the last line should work. You could use awk for this but really tail is the way to go.

waqasdaar 01-10-2009 02:02 PM

Can you tell me how can i achieve this using awk. because I havent use awk yet.

Sergei Steshenko 01-10-2009 02:18 PM

Quote:

Originally Posted by waqasdaar (Post 3403793)
i have tried a lot with tail as well as sed but i does not work.
any other idea ?

Ever heard of difference between stdout and stderr ?

Ever tried to figure out which of the two your program uses ?

Ever heard of redirection of the above two ?

As it was already pointed out, you named the thread very poorly.
This often is an indication of lack of desire to go into details.

Disillusionist 01-10-2009 02:26 PM

Code:

mkfifo /tmp/my_fifo
./tt.sh /home/JHON/Videos/Ala_sinistra.avi > /tmp/my_fifo 2>&1 &
tail -1 /tmp/my_fifo

should work...
:D

waqasdaar 01-10-2009 02:36 PM

frame= 625 fps=103 q=1.6 size= 12151kB time=24.96 bitrate=3988.0kbits

When I execute my script last line continusely changing its value and I just want to print that, even I tried all method its does nor work with 'tail' command. Even I have tried with 'sed', tried to only print the line starting with 'frame='
but it also does not work.

waqasdaar 01-10-2009 02:44 PM

Thanks borther,

I have tried this before. but it doest not work :)

Sergei Steshenko 01-10-2009 02:47 PM

Quote:

Originally Posted by waqasdaar (Post 3403837)
Thanks borther,

I have tried this before. but it doest not work :)

You haven't published full command lines which allegedly do not work.

PTrenholme 01-10-2009 03:02 PM

waqasdaar, you've fallen into a "Linux mindset" trap. (This is almost as bad as falling amongst thieves, but, I hope, not quite.)

You posted a (poorly titled) query in the programming forum which, to most of us, implies either that you are, or that you wish to be, knowledgeable about programming, but don't know how to proceed. Therefore the advice you're getting is focused on helping you learn "The Linux Way," not a specific answer to your question.

Your question was, in fact, answered by the first response where you were directed to read the manual explaining the use of the tail command. The mind set here is that simply saying "add 2>&1 | tail -1 at the end of the command" is, to quote from the old parable, "giving you a fish" whilst saying "man tail" is "teaching you how to fish."

The additional reading to understand the 2>&1 and "|" is found in info bash, which also covers much other useful shell scripting information. Unless your shell command (tt.sh) is generating output to stderr, the 2>1& prior to the pipe (|) is unnecessary.

Sergei Steshenko 01-10-2009 03:29 PM

Quote:

Originally Posted by PTrenholme (Post 3403849)
waqasdaar, you've fallen into a "Linux mindset" trap. (This is almost as bad as falling amongst thieves, but, I hope, not quite.)

You posted a (poorly titled) query in the programming forum which, to most of us, implies either that you are, or that you wish to be, knowledgeable about programming, but don't know how to proceed. Therefore the advice you're getting is focused on helping you learn "The Linux Way," not a specific answer to your question.

Your question was, in fact, answered by the first response where you were directed to read the manual explaining the use of the tail command. The mind set here is that simply saying "add 2>&1 | tail -1 at the end of the command" is, to quote from the old parable, "giving you a fish" whilst saying "man tail" is "teaching you how to fish."

The additional reading to understand the 2>&1 and "|" is found in info bash, which also covers much other useful shell scripting information. Unless your shell command (tt.sh) is generating output to stderr, the 2>1& prior to the pipe (|) is unnecessary.

I think I know what the OP's problem is, but, as you said, I'd like to see some indication that he/she really wants to learn how to catch fish and not only how to eat it.

ErV 01-10-2009 04:56 PM

Quote:

Originally Posted by waqasdaar (Post 3403837)
but it doest not work :)

This doesn't tell anything useful.
Post how exactly you tried it (i.e. complete command) and how exactly it didn't work (what you expected, and what you've got).

waqasdaar 01-12-2009 10:08 AM

I am using "ffmpeg" which is a command line tool to convert multimedia files between formats. In a script (tt.sh) i am using the ffmpeg comand like this

ffmpeg -i $1 -b 4000k -minrate 4000k -maxrate 4000k -bufsize 1835k temp.m2v > temp; tail -1 temp

After that when I run the script

./tt.sh /home/JHON/Videos/Ala_sinistra.avi

It print some thing like this

FFmpeg version git-5a82e37, Copyright (c) 2000-2008 Fabrice Bellard, et al.
configuration:
libavutil 49.12. 0 / 49.12. 0
libavcodec 52. 3. 0 / 52. 3. 0
libavformat 52.23. 1 / 52.23. 1
libavdevice 52. 1. 0 / 52. 1. 0
built on Nov 17 2008 15:13:29, gcc: 3.3.5 (Debian 1:3.3.5-13)

Seems stream 0 codec frame rate differs from container frame rate: 30000.00 (30000/1) -> 25.00 (25/1)
Input #0, avi, from '/home/waqasdaar/Videos/Ala_sinistra.avi':
Duration: 00:04:07.28, start: 0.000000, bitrate: 754 kb/s
Stream #0.0: Video: mpeg4, yuv420p, 320x240 [PAR 1:1 DAR 4:3], 25.00 tb(r)
Stream #0.1: Audio: mp3, 44100 Hz, stereo, s16, 160 kb/s
File 'temp.m2v' already exists. Overwrite ? [y/N] Y
Output #0, mpeg2video, to 'temp.m2v':
Stream #0.0: Video: mpeg2video, yuv420p, 320x240 [PAR 1:1 DAR 4:3], q=2-31, 4000 kb/s, 25.00 tb(c)
Stream mapping:
Stream #0.0 -> #0.0
Press [q] to stop encoding
Compiler did not align stack variables. Libavcodec has been miscompiled
and may be very slow or crash. This is not a bug in libavcodec,
but in the compiler. You may try recompiling using gcc >= 4.2.
Do not report crashes to FFmpeg developers.
frame= 777 fps=102 q=2.0 size= 15120kB time=31.04 bitrate=3990.4kbits/s

The bold line continusely changing its value after converting the whole media file it prints at the end

video:120686kB audio:0kB global headers:0kB muxing overhead 0.000000%

I just trying to achieve that it only prints the Bold line. after it finish script return me the control back. Hope now you understand the problem.

Sorry guys if I didnot mention the problem clearly.


Thanks in Advanced.


All times are GMT -5. The time now is 07:53 AM.