bash - 将 xml 文件从文件夹移动到另一个文件夹取决于 bash shell 中的条件
问题描述
我只需要根据 xml 标签注释将 xml 文件从文件夹移动到另一个文件夹,例如:
If :
1- comment tag is Student1 will be move to folder Student_1
2- comment tag is Student2 will be move to folder Student_2
xml:
<?xml version = "1.0" encoding = "UTF-8" ?>
<!--Student1 grades are uploaded by months-->
<class_list>
<student>
<name>Tanmay</name>
<grade>A</grade>
</student>
</class_list>
任何建议,
先感谢您
解决方案
Grep
有一个有用的退出状态,所以应该这样做。
#!/usr/bin/env bash
if grep -q '^<!--Student1.*-->$' file.xml; then
echo cp file.xml Student_1
elif grep -q '^<!--Student2.*-->$' file.xml; then
echo cp file.xml Student_2
fi
echo
如果您对输出感到满意,请删除's,以便 cp 可以实际复制文件。
推荐阅读
- office-js - 同时部署 VSTO 和 Web Outlook 加载项
- angular - 重新路由后 Skype 按钮不显示
- c# - 使用 Asp net 从客户端运行查询到 sql 服务器的最安全方法
- python-3.x - 如何从 Google Search Console API 获取用户信息
- google-analytics - 将 GA 和 GTM 的设置从一个帐户复制到另一个帐户而不复制数据
- jestjs - 如何安排 Jest 测试每小时运行一次
- javascript - D3Node getComputedTextLength() 不是函数
- c++ - 从单词中获取第一个字符并根据任何条件替换为 *
- angular - 在 forkjoin TS 中使用 await
- ios - 如何从设置中更改应用程序的字体?