[英]How can I replace a specific line of a file in bash script?
I have a file inside the one directory, I want to replace one specific line with another line. 我在一个目录中有一个文件,我想用另一行替换一个特定的行。
In my case the line is - "password requisite pam_pwquality.so" and I want to make it as 在我的情况下,该行是-“ password Requirement pam_pwquality.so”,我想将其设置为
"#password requisite pam_pwquality.so". “ #password必需的pam_pwquality.so”。
I tried like this: 我这样尝试过:
cat test1 | while read line
do
if grep -q "$str" test1; then
echo "found"
sed -i -e "s/${str}/${str1}/g" test1
fi
but it is showing multiple found statements but I am having only one copy of this line. 但是它显示了多个找到的语句,但是我只有这一行的一个副本。
$ x='password requisite pam_pwquality.so'
$ sed -i "s/\($x\)/#\1/" file
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.