我需要从日志文件中选择某些行并将它们保存到文本文件中。我尝试了以下操作,但没有一个按预期工作。文件“todel.txt”显示为 0 字节。
tail -f general.log | grep Some_word > >(tee -a todel.txt)
tail -f general.log | grep Some_word ; tee todel.txt
tail -f general.log | grep Some_word | tee -a todel.txt
Run Code Online (Sandbox Code Playgroud) 我可以将错误保存在与标准输出相同的文件中。我在下面使用了这种方法。问题是错误输出“总是”显示在顶部。在下面给出的示例中,错误与无法保存值“india”的倒数第二个 sql 命令有关。错误消息应显示在该语句旁边,而不是文件顶部。
# cat import.txt
drop table if exists testme;
create table testme (id int , name varchar(255));
insert into testme values (1, 'abc');
insert into testme values (2, 'abc', 'india');
insert into testme values (3, 'xyz');
# mysql test -vvf < import.txt >standard.txt 2>&1
# cat standard.txt
ERROR 1136 (21S01) at line 5: Column count doesn't match value count at row 1
--------------
drop table if exists testme
--------------
Query OK, 0 rows affected
--------------
create table testme …Run Code Online (Sandbox Code Playgroud)