我想学习如何从txt文件中删除包含用户在变量中输入的单词的行 我尝试过grep -v但是然后清除了文件的全部内容 救命?!!!
答案 0 :(得分:1)
以下是一个如何存档的示例程序:
将其保存在example.sh
:
#!/bin/bash
word="$1"
grep -F -v "$word"
将其保存在test.txt
:
Hello world
foo bar
baz bau
调用程序并将其与标准输入文件test.txt一起提供:
chmod u+x example.sh # Need to do this only once per script (*.sh file)
./example.sh Hello < test.txt
输出(&#34; Hello world&#34;行被删除):
foo bar
baz bau