Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux sed命令未按预期工作_Linux_Unix_Sed - Fatal编程技术网

Linux sed命令未按预期工作

Linux sed命令未按预期工作,linux,unix,sed,Linux,Unix,Sed,使用sed命令尝试匹配一个值,然后追加一个值。 Comd在没有变量的情况下工作正常,但无法按预期传递变量 这个通讯器工作得很好 sed -i 's/\( *OOZIEUSERS1 *\)[^ ]*\(.*\)*$/\1, test1,\2/' sudo_file.txt 但运行tru Variable时,其不工作:- #!/bin/bash -x read -p "Enter the reference account name : " ACC read -p "Enter the user

使用sed命令尝试匹配一个值,然后追加一个值。 Comd在没有变量的情况下工作正常,但无法按预期传递变量

这个通讯器工作得很好

sed -i 's/\( *OOZIEUSERS1 *\)[^ ]*\(.*\)*$/\1, test1,\2/' sudo_file.txt
但运行tru Variable时,其不工作:-

#!/bin/bash -x
read -p "Enter the reference account name : " ACC
read -p "Enter the user name to be inserted into VISUDO : " UNAME
sed -i  's/\( *$ACC *\)[^ ]*\(.*\)*$/\1, $UNAME,\2/' sudo_file.txt

如果希望bash展开变量,则应使用双引号

sed -i  "s/\( *$ACC *\)[^ ]*\(.*\)*$/\1, $UNAME,\2/" sudo_file.txt

使用双引号展开变量尝试使用双引号而不是单引号与sed一起展开。
sed-i“s/\(*$ACC*\)[^]*\(*\)*$/\1,$UNAME\2/“sudo_file.txt
。还可以看到这个答案:如果我想确保在ACC的开头而不是结尾添加UNAME,我如何更改命令。这是另一个问题。。。如果有任何答案,首先搜索stackoverflow;如果没有,请添加另一个问题并提供更多信息:您得到的输出是什么;你想要什么,你有没有试过,。。。