shell - 用文件中的shell脚本替换字符
问题描述
我在 unix 中有一个 txt 文件,其中有一个特殊字符。我需要替换特殊字符的所有实例在 shell 脚本中我该怎么做?
这是我的代码。我需要在 sftp 之前替换所有特殊字符
elif [[ $module = "get_ce_xml_to_xcent" ]]
then
echo "get_ce_xml_to_xcent"
ssh -T -o ConnectTimeout=5 oracle@GL-REL-CEAPP.abanet.local <<ENDSSH
cd /srv/exports/promotion
chmod 777 *.txt
sftp oracle@GL-REL-XSTAPP <<ENDFTP
cd /fileuploads/org69
mput *.txt
quit
ENDFTP
#for i in `ls *.txt 2>/dev/null`; do echo $i; mv $i /srv/exports/promotion/arch/$i.`date "+%Y%m%d%H%M%S"` ; done
mv *.txt arch/
exit
ENDSSH
解决方案
假设您有一个在多个位置.txt
包含特殊字符()的文件:ý
mayankp@mayank:~/$ cat test.txt
"123","qweeerr","qqqqqq ý
rrrrr
hhhhhh",ý "sdfsfs"
ý
您可以从如下文件中替换:
mayankp@mayank:~/$ sed -i 's/ý//g' test.txt
mayankp@mayank:~/$ cat test.txt
"123","qweeerr","qqqqqq
rrrrr
hhhhhh", "sdfsfs"
您只需要在命令sed -i 's/ý//g' test.txt
之前在脚本中附加该行sftp
。
让我知道它是否有效。
推荐阅读
- python - 尝试将文本与参数之间的空格结合起来
- python - 如何在python中使用收据打印机打印收据
- javascript - TextField 和 Select 不会改变 - React JS
- flutter - 颤振邮件包,附件
- javascript - 制作 JS MIC 噪音反应器 - (对 MIC 声音/噪音作出反应的声音可视化)垂直朝左而不是水平 + 在页面加载时运行
- java - 如何将带有id的json转换为实体
- spring - 批处理文件中的 Spring Boot 输出
- tensorflow - 如何在 Tensorflow Keras API 中使用配对数据集样本创建联合损失?
- pine-script - 蜡烛的开盘价和收盘价之间的平均距离
- c# - Blazor - 使用 localstorage OnAfterRenderAsync 恢复多个依赖下拉列表