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 |
man tail
|
Please use a title that is relevant to your question.
"Urgent Help Needed" is often ignored. |
i have tried a lot with tail as well as sed but i does not work.
any other idea ? |
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.
|
Can you tell me how can i achieve this using awk. because I havent use awk yet.
|
Quote:
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. |
Code:
mkfifo /tmp/my_fifo :D |
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. |
Thanks borther,
I have tried this before. but it doest not work :) |
Quote:
|
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. |
Quote:
|
Quote:
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). |
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. |
Quote:
Do these things mentioned above, before posting back about how it doesn't work, and asking the same question again. |
Quote:
Try to understand/answer these two questions first - in whatever order. Maybe start from the simpler one - about stderr vs stdout - do you know how to find this out ? Do you understand why these questions are asked ? |
As previously mentioned by PTrenholme and indicated by others, you need to understand output redirection.
In a shell, type man bash and read the section on REDIRECTION. The output you are getting is from stderr instead of stdout When you redirect output using the > without a file descriptor, bash assumes that you mean stdout (File descriptor 1). Therefore: Code:
ffmpeg -i $1 -b 4000k -minrate 4000k -maxrate 4000k -bufsize 1835k temp.m2v > temp Code:
ffmpeg -i $1 -b 4000k -minrate 4000k -maxrate 4000k -bufsize 1835k temp.m2v 1> temp Code:
ffmpeg -i $1 -b 4000k -minrate 4000k -maxrate 4000k -bufsize 1835k temp.m2v 1> temp 2> errors If you look at my previous post you would see something like: Code:
2>&1 What we have been saying, is that it is in your best interest to understand this as opposed to copy typing. |
All times are GMT -5. The time now is 10:26 AM. |