Unix, создание файла на основе команды [дубликат]

0
16.03.2016, 17:32
1 ответ

Ну, в основном, используйте перенаправление вывода

my command|grep stackoverflow > file       #writes output to <file>
my command|grep stackoverflow >> file      #appends <file> with output
my command|grep stackoverflow|tee file     #writes output to <file> and still prints to stdout
my command|grep stackoverflow|tee -a file  #appends <file> with output and still prints to stdout

Труба берет все из stdout и дает это в качестве ввода команде, которая следует за ней. Итак:

echo "this is a text" # prints "this is a text"
ls                    # prints the contents of the current directory

grep теперь будет пытаться найти подходящее регулярное выражение в полученном входе.

echo "my command" | grep stackoverflow  #will find no matching line.
echo "my command" | grep command        #will find a matching line.

Я полагаю, что "моя команда" означает команду, а не сообщение "моя команда"

0
28.01.2020, 04:51

Теги

Похожие вопросы