我尝试遵循 shell 脚本,它应该替换所有 xml 文件名中的空格
for xml_file in $(find $1 -name "* .xml" -type f);
do
echo "removing spaces from XML file:" $xml_file
mv "$xml_file" "${xml_file// /_}";
done
Run Code Online (Sandbox Code Playgroud)
假设,我有名称为 的 xml 文件xy z.xml,然后它给出:
removing spaces from XML file: /home/krishna/test/xy
mv: cannot stat `/home/krishna/test/xy': No such file or directory
removing spaces from XML file: .xml
mv: cannot stat `z.xml': No such file or directory
Run Code Online (Sandbox Code Playgroud) 我尝试按照 shell 脚本删除所有带下划线的空格:
find $1 -depth -name "* *" -print0 | \
while read -d $'\0' f; do mv -v "$f" "${f// /_}"; done
Run Code Online (Sandbox Code Playgroud)
如果我有一个目录,/home/user/g h/y h/u j/它会将y h目录修改为y_h,然后它会给出以下错误/home/user/g h/y h/u j:
No such file or directory
Run Code Online (Sandbox Code Playgroud) 例如,我想将标签中的字段转换为该标签内的标签
<book name="Data Structure" price="250" pages="350"/>
Run Code Online (Sandbox Code Playgroud)
到
<book name="Data Structure">
<price>250</price>
<pages>350</pages>
</book>
Run Code Online (Sandbox Code Playgroud)
xmlstarlet我想使用或在 Linux 命令行中执行此操作sed。
我正在尝试使用 sed 脚本在标签末尾添加字段。假设我在 XML 文件中有一个标签:
<book name="Sed tutorial" price="250"/>
Run Code Online (Sandbox Code Playgroud)
现在我想Book_Width="A"在<book/>标签结束后添加字段,以便我的标签变为:
<book name="Sed tutorial" price="250" Book_Width="A"/>
Run Code Online (Sandbox Code Playgroud)
我试过sed:
sed '/<book "[^>]*>/ a Book_Width="A"'
Run Code Online (Sandbox Code Playgroud)
但它给出了:
<book name="Sed tutorial" price="250"/>
Book_Width="A"
Run Code Online (Sandbox Code Playgroud) files ×2
find ×2
mv ×2
rename ×2
shell-script ×2
xml ×2
command-line ×1
directory ×1
sed ×1
xmlstarlet ×1