LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-10-2009, 12:29 PM   #1
waqasdaar
Member
 
Registered: Jan 2009
Location: Stockholm Sweden
Distribution: Ubuntu 9.10
Posts: 57

Rep: Reputation: 15
Question 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
 
Old 01-10-2009, 01:07 PM   #2
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
man tail
 
Old 01-10-2009, 01:14 PM   #3
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,529

Rep: Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899
Please use a title that is relevant to your question.
"Urgent Help Needed" is often ignored.
 
Old 01-10-2009, 01:23 PM   #4
waqasdaar
Member
 
Registered: Jan 2009
Location: Stockholm Sweden
Distribution: Ubuntu 9.10
Posts: 57

Original Poster
Rep: Reputation: 15
Question

i have tried a lot with tail as well as sed but i does not work.
any other idea ?
 
Old 01-10-2009, 01:34 PM   #5
bgeddy
Senior Member
 
Registered: Sep 2006
Location: Liverpool - England
Distribution: slackware64 13.37 and -current, Dragonfly BSD
Posts: 1,810

Rep: Reputation: 232Reputation: 232Reputation: 232
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.
 
Old 01-10-2009, 02:02 PM   #6
waqasdaar
Member
 
Registered: Jan 2009
Location: Stockholm Sweden
Distribution: Ubuntu 9.10
Posts: 57

Original Poster
Rep: Reputation: 15
Question

Can you tell me how can i achieve this using awk. because I havent use awk yet.
 
Old 01-10-2009, 02:18 PM   #7
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by waqasdaar View Post
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.
 
Old 01-10-2009, 02:26 PM   #8
Disillusionist
Senior Member
 
Registered: Aug 2004
Location: England
Distribution: Ubuntu
Posts: 1,039

Rep: Reputation: 98
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...
 
Old 01-10-2009, 02:36 PM   #9
waqasdaar
Member
 
Registered: Jan 2009
Location: Stockholm Sweden
Distribution: Ubuntu 9.10
Posts: 57

Original Poster
Rep: Reputation: 15
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.
 
Old 01-10-2009, 02:44 PM   #10
waqasdaar
Member
 
Registered: Jan 2009
Location: Stockholm Sweden
Distribution: Ubuntu 9.10
Posts: 57

Original Poster
Rep: Reputation: 15
Thanks borther,

I have tried this before. but it doest not work
 
Old 01-10-2009, 02:47 PM   #11
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by waqasdaar View Post
Thanks borther,

I have tried this before. but it doest not work
You haven't published full command lines which allegedly do not work.
 
Old 01-10-2009, 03:02 PM   #12
PTrenholme
Senior Member
 
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 4,187

Rep: Reputation: 354Reputation: 354Reputation: 354Reputation: 354
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.
 
Old 01-10-2009, 03:29 PM   #13
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by PTrenholme View Post
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.
 
Old 01-10-2009, 04:56 PM   #14
ErV
Senior Member
 
Registered: Mar 2007
Location: Russia
Distribution: Slackware 12.2
Posts: 1,202
Blog Entries: 3

Rep: Reputation: 62
Quote:
Originally Posted by waqasdaar View Post
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).
 
Old 01-12-2009, 10:08 AM   #15
waqasdaar
Member
 
Registered: Jan 2009
Location: Stockholm Sweden
Distribution: Ubuntu 9.10
Posts: 57

Original Poster
Rep: Reputation: 15
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.
 
  


Reply

Tags
bash, scripting



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Urgent help needed! Please!!! RobynD Linux - Newbie 6 11-03-2007 10:29 AM
Urgent - Help Needed rigel_kent Linux - General 1 07-21-2005 08:20 AM
Please Urgent Help Needed Here !!! dezeque Linux - General 6 05-26-2005 03:37 PM
Urgent help needed the_twister Linux - Security 4 08-13-2003 09:58 AM
Urgent help needed J_Szucs Linux - Newbie 7 07-09-2002 09:39 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:22 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration