Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.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
Replace 查找并重新排列包含多个目录中文件引号的字符串-unix aix_Replace_Sed_Find_Aix - Fatal编程技术网

Replace 查找并重新排列包含多个目录中文件引号的字符串-unix aix

Replace 查找并重新排列包含多个目录中文件引号的字符串-unix aix,replace,sed,find,aix,Replace,Sed,Find,Aix,下面是一个场景。我想在安装中的100个文件中将以下值从true更改为false,但无法理解该命令,并且已经为此工作了几天。我有一个简单的脚本,它查找一个文件的所有实例,并将结果存储在一个文件中。我正在使用此命令查找需要修改的文件: find /directory -type f \ ( -name 'filename' \) > file_instances.txt 现在我要做的是运行以下命令或其变体,以修改以下值: sed 's/directoryBrowsingEnabled="fa

下面是一个场景。我想在安装中的100个文件中将以下值从true更改为false,但无法理解该命令,并且已经为此工作了几天。我有一个简单的脚本,它查找一个文件的所有实例,并将结果存储在一个文件中。我正在使用此命令查找需要修改的文件:

find /directory -type f \ ( -name 'filename' \) > file_instances.txt
现在我要做的是运行以下命令或其变体,以修改以下值:

sed 's/directoryBrowsingEnabled="false"/directoryBrowsingEnabled="true"/g' $i > $i
当我测试上述命令时,当它试图替换字符串时,它已将该文件删除,但如果我针对单个文件运行该命令,则更改是正确的

有人能解释一下吗

先谢谢你


对我有效的方法如下:

您可以使用
-i
选项调用sed,而不是执行
$i
。您甚至可以通过添加后缀来备份旧文件,以防出现问题

sed -e 'command' -i.backup myfile.txt
这将在myfile.txt上执行
命令
替换,并将旧文件保存在myfile.txt.backup中

编辑:
不使用
-i
可能确实会导致空白文件,这是因为unix不希望您同时读写(这会导致争用情况)

您可以通过一些简单的
cat
命令来说服自己:

$ echo "This is a test" > test.txt
$ cat test.txt > test.txt # This will return an error cat being smart
$ cat <test.txt >test.txt # This will blank the file, cat being not that smart
$echo“这是一个测试”>test.txt
$cat test.txt>test.txt#这将返回一个错误cat正在智能化
$cat test.txt#这将清空文件,因为cat没有那么聪明

在AIX上,您可能缺少sed的
-i
选项。悲哀的您可以制作一个脚本,将每个文件移动到一个tmp文件,并(使用sed)重定向到原始文件,或者尝试在vi中使用here结构:

cat file_instances.txt | while read file; do
   vi ${file}<<END >/dev/null 2>&1
:1,$ s/directoryBrowsingEnabled="false"/directoryBrowsingEnabled="true"/g
:wq
END
done
cat file_instances.txt |读取文件时;做
vi${file}&1
:1,$s/directoryBrowsingEnabled=“false”/directoryBrowsingEnabled=“true”/g
:wq
结束
完成

你的问题以悬念的方式结束。。。另外,你的问题并不是因为有引号,所以你可能想更改你的标题。