I am using ffmpeg to get the meta info of an audio clip. But I am unable to grep it.
$ ffmpeg -i 01-Daemon.mp3 |grep -i Duration
FFmpeg version SVN-r15261, Copyright (c) 2000-2008 Fabrice Bellard, et al.
configuration: --prefix=/usr --bindir=/usr/bin
--datadir=/usr/share/ffmpeg --incdir=/usr/include/ffmpeg --libdir=/usr/lib
--mandir=/usr/share/man --arch=i386 --extra-cflags=-O2
...
I checked, this ffmpeg output is directed to stderr.
$ ffmpeg -i 01-Daemon.mp3 2> /dev/null
So I think that grep is unable to read error stream to catch matching lines. How can we enable grep to read error stream?
Using nixCraft link, I redirected standard error stream to standard output stream, then grep worked.
$ ffmpeg -i 01-Daemon.mp3 2>&1 | grep -i Duration
Duration: 01:15:12.33, start: 0.000000, bitrate: 64 kb/s
But what if we do not want to redirect stderr to stdout?
grep
can only operate on stdout (Although I can't find the canonical source to back that up), which means that any stream needs to be converted to stdout first.grep
can only operate on stdin. It's the pipe created by the shell that connects grep's stdin to the other command's stdout. And the shell can only connect an stdout to an stdin.