Unix将grep命令重定向到文件

问题描述 投票:0回答:1

对于作业,我必须执行以下操作:'抓取所有以大写字母开头的行,这些行在“ test1.txt”中仅包含字母(大写或小写)。重定向此命令的输出以附加到现有的“ output2.txt”。'

我尝试使用

grep ^[A-Z]*[a-z] > test1.txt >> output2.txt

但是它给我一个错误,提示“歧义输出重定向”。我仍在学习如何使用Unix,所以不确定如何修复它。

unix grep command
1个回答
0
投票

为了避免进行分配,我将给出一个简单的示例,说明如何使用cat进行输出重定向。您可以翻译为grep

$ # Print file to standard output
$ cat test1.txt
abc
Abc
9B
$ # Print to another file, overwriting existing file
$ cat test1.txt > output2.txt
$ cat output2.txt
abc
Abc
9B
$ # Print to another file, appending to existing file
$ cat test1.txt >> output2.txt
$ cat output2.txt
abc
Abc
9B
abc
Abc
9B
© www.soinside.com 2019 - 2024. All rights reserved.