Как перенаправить вывод команды КУДА-НИБУДЬ, чтобы его обработать комндой grep?

На самом деле это единственный раздел про unix на этом форуме

Модераторы: /dev/random, Модераторы разделов

Ответить
Аватара пользователя
жучара
Сообщения: 937
ОС: астралинукс

Как перенаправить вывод команды КУДА-НИБУДЬ, чтобы его обработать комндой grep?

Сообщение жучара »

Друзья! Вот эта команда:

Shell

find foo -name "*.mp3" -exec mpg123 -t {} \;
Что делает: в папке ищет файлы *.mp3 и по каждому файлу выводит информацию (не проигрывая). Простыня, короче на выходе. Мне эту инфу нужно потом обработать grep-ом
простыня
user@astra:~/Desktop$ find foo -name "*.mp3" -exec mpg123 -t {} \;
High Performance MPEG 1.0/2.0/2.5 Audio Player for Layers 1, 2 and 3
version 1.23.8; written and copyright by Michael Hipp and others
free software (LGPL) without any warranty but with best wishes

Directory: foo/

Terminal control enabled, press 'h' for listing of keys and functions.

Playing MPEG stream 1 of 1: Scorpions – When You Came Into My Life.mp3 ...

MPEG 1.0 L III cbr320 44100 stereo

Title: When You Came Into My Life Artist: Scorpions [waptorrent.ru]
Comment: http://waptorrent.ru Album: Pure Instinct
Year: 2015 Genre: Rock

[5:13] Decoding of Scorpions – When You Came Into My Life.mp3 finished.
High Performance MPEG 1.0/2.0/2.5 Audio Player for Layers 1, 2 and 3
version 1.23.8; written and copyright by Michael Hipp and others
free software (LGPL) without any warranty but with best wishes

Directory: foo/

Terminal control enabled, press 'h' for listing of keys and functions.

Playing MPEG stream 1 of 1: Scorpions – When The Smokie Is Going Down.mp3 ...

MPEG 1.0 L III cbr320 44100 stereo

Title: When The Smokie Is Going Down Artist: Scorpions
Comment: Album:
Year: 2004 Genre: Unknown

[3:50] Decoding of Scorpions – When The Smokie Is Going Down.mp3 finished.
High Performance MPEG 1.0/2.0/2.5 Audio Player for Layers 1, 2 and 3
version 1.23.8; written and copyright by Michael Hipp and others
free software (LGPL) without any warranty but with best wishes

Directory: foo/

Terminal control enabled, press 'h' for listing of keys and functions.

Playing MPEG stream 1 of 1: Скорпионс – Still Loving You.mp3 ...

MPEG 1.0 L III cbr128 44100 stereo

Title: Still Loving You Artist: Скорпионс
Comment: Album:
Year: Genre: Other
Note: Illegal Audio-MPEG-Header 0x00000000 at offset 5953499.
Note: Trying to resync...
Note: Hit end of (available) data during resync.

[6:11] Decoding of Скорпионс – Still Loving You.mp3 finished.
High Performance MPEG 1.0/2.0/2.5 Audio Player for Layers 1, 2 and 3
version 1.23.8; written and copyright by Michael Hipp and others
free software (LGPL) without any warranty but with best wishes

Directory: foo/

Terminal control enabled, press 'h' for listing of keys and functions.

Playing MPEG stream 1 of 1: scorpions_always_somewhere_(NaitiMP3.ru).mp3 ...

MPEG 1.0 L III cbr320 44100 j-s

Title: Always Somewhere Artist: Scorpions
Comment: Album: The Best Ballads
Year: 1995 Genre: Hard Rock

[4:58] Decoding of scorpions_always_somewhere_(NaitiMP3.ru).mp3 finished.
High Performance MPEG 1.0/2.0/2.5 Audio Player for Layers 1, 2 and 3
version 1.23.8; written and copyright by Michael Hipp and others
free software (LGPL) without any warranty but with best wishes

Directory: foo/

Terminal control enabled, press 'h' for listing of keys and functions.

Playing MPEG stream 1 of 1: Scorpions – White Dove.mp3 ...

MPEG 1.0 L III cbr320 44100 stereo

Title: White Dove Artist: Scorpions
Comment: Album:
Year: 1994 Genre: Hard Rock

[4:22] Decoding of Scorpions – White Dove.mp3 finished.
High Performance MPEG 1.0/2.0/2.5 Audio Player for Layers 1, 2 and 3
version 1.23.8; written and copyright by Michael Hipp and others
free software (LGPL) without any warranty but with best wishes

Directory: foo/

Terminal control enabled, press 'h' for listing of keys and functions.

Playing MPEG stream 1 of 1: scorpions_in_trance_(NaitiMP3.ru).mp3 ...

MPEG 1.0 L III cbr192 44100 stereo

Title: In Trance Artist: Scorpions
Comment: Klaus Meine - vocals;
Rudolf Schenker - guitars;
Uli Roth - guitars, vocals;
Herman Rarebell - drums;
Francis Buchholz - bass.
Album: Tokyo Tapes
Year: 1979 Genre: Hard Rock

[5:28] Decoding of scorpions_in_trance_(NaitiMP3.ru).mp3 finished.
High Performance MPEG 1.0/2.0/2.5 Audio Player for Layers 1, 2 and 3
version 1.23.8; written and copyright by Michael Hipp and others
free software (LGPL) without any warranty but with best wishes

Directory: foo/

Terminal control enabled, press 'h' for listing of keys and functions.

Playing MPEG stream 1 of 1: Scorpions – Send me an angel.mp3 ...

MPEG 1.0 L III cbr128 44100 stereo

Title: Send Me An Angel Artist: Scorpions
Comment: Album:
Year: 2002 Genre: Unknown

[4:33] Decoding of Scorpions – Send me an angel.mp3 finished.
High Performance MPEG 1.0/2.0/2.5 Audio Player for Layers 1, 2 and 3
version 1.23.8; written and copyright by Michael Hipp and others
free software (LGPL) without any warranty but with best wishes

Directory: foo/

Terminal control enabled, press 'h' for listing of keys and functions.

Playing MPEG stream 1 of 1: scorpions-wind-of-change-320_(mp3CC.com).mp3 ...

MPEG 1.0 L III cbr320 44100 j-s

Title: Wind Of Change Artist: Scorpions
Comment: Album: The Platinum Collection CD 2
Year: 2004 Genre: Hard Rock

[5:12] Decoding of scorpions-wind-of-change-320_(mp3CC.com).mp3 finished.
High Performance MPEG 1.0/2.0/2.5 Audio Player for Layers 1, 2 and 3
version 1.23.8; written and copyright by Michael Hipp and others
free software (LGPL) without any warranty but with best wishes

Directory: foo/

Terminal control enabled, press 'h' for listing of keys and functions.

Playing MPEG stream 1 of 1: Scorpions – Holiday.mp3 ...

MPEG 1.0 L III cbr320 44100 j-s

Title: Holiday Artist: Scorpions
Comment: Album:
Year: 2013 Genre: Rock

[6:33] Decoding of Scorpions – Holiday.mp3 finished.
user@astra:~/Desktop$
А как обработать-то?

++++++++++++++++++++++++++++++++++++++++

Shell

find foo -name "*.mp3" -exec mpg123 -t {} \; > bar.txt
И опять простыня вывода, bar.txt пустой.

++++++++++++++++++++++++++++++++++++++++

Shell

bar=$(find foo -name "*.mp3" -exec mpg123 -t {} \;)
И опять простыня вывода, переменная bar ничего не содержит

++++++++++++++++++++++++++++++++++++++++

Сразу grep-у дать на обработку? Так не обрабатывает, простыню выводит.

Shell

find foo -name "*.mp3" -exec mpg123 -t {} \; | grep MPEG
И так далее, чего я только не пробовал. Грустно. Что же делать? Спасибо, кто откликнется.
Я просто читаю маны.
Спасибо сказали:
Аватара пользователя
Vascom
Сообщения: 1699
ОС: Fedora 32

Re: Как перенаправить вывод команды КУДА-НИБУДЬ, чтобы его обработать комндой grep?

Сообщение Vascom »

Попробуй так
find foo -name "*.mp3" -exec mpg123 -t {} \; &> bar.txt
Спасибо сказали:
Аватара пользователя
жучара
Сообщения: 937
ОС: астралинукс

Re: Как перенаправить вывод команды КУДА-НИБУДЬ, чтобы его обработать комндой grep?

Сообщение жучара »

Да, получилось, спасибо, но мне не понять, а что не так-то:?

Shell

find foo -name "*.mp3" -exec mpg123 -t {} \; 2>bar.txt
Оно так тоже работает... Получается весь-весь вывод- одна большая ошибка! Как с этим жить- не понимаю...
Я просто читаю маны.
Спасибо сказали:
Аватара пользователя
Vascom
Сообщения: 1699
ОС: Fedora 32

Re: Как перенаправить вывод команды КУДА-НИБУДЬ, чтобы его обработать комндой grep?

Сообщение Vascom »

Спроси у mpg123 почему его вывод идёт на stderr. Создай багрепорт.
Спасибо сказали:
Ответить