更换一个的话,我需要一个UNIX shell脚本,在执行时接受的句子和替换另一个词一个给定的词。shell脚本在给定的句子
-1
A
回答
0
用sed:
SED的/源/目的/'file_with_sentence.txt
- 来源是搜索词
- destiantion是更换
- file_with_sentence ...是海基会解释
你可以将它包装到一些unix shell脚本中(你没有告诉哪个shel l为你使用)
甚至更好:
回声 “这是我的一句” | SED的/源/目的/'
1
如果你需要一个命令来做到这一点,尝试SED。
例如,要在句子hello world
与goodbye
替换hello
:
$ sed 's/hello/goodbye/g' <<< "hello world"
goodbye world
如果你想在这个bash脚本:
#!/bin/bash
if [[ $# -lt 3 ]]
then
echo "Usage: $(basename $0) word replacement sentence" >&2
exit 1
fi
word="$1"
replacement="$2"
sentence="$3"
echo "${3//$1/$2}"
例子:
$ replace.sh hello goodbye "hello world"
goodbye world
相关问题
- 1. 句子问题(shell脚本)
- 2. 将子shell脚本的值返回给父脚本
- 3. bash/shell脚本语句
- 4. shell脚本:if语句
- 5. 在如果子句中的shell脚本詹工作里面
- 6. shell脚本:嵌套的子shell ++
- 7. Shell脚本如果语句子句总是执行
- 8. 多条语句在shell脚本
- 9. 从子shell脚本中的函数退出到父shell脚本
- 10. 在JavaScript中执行Shell脚本如果子句
- 11. EVAL在shell脚本给错误
- 12. shell脚本 - (删除子串)
- 13. shell的shell脚本
- 14. shell脚本的if语句麻烦
- 15. 如何编写在给定时间执行的shell脚本
- 16. 在shell脚本
- 17. $?在shell脚本
- 18. 在shell脚本
- 19. 在shell脚本
- 20. 在shell脚本
- 21. 编写shell脚本的shell脚本
- 22. Shell脚本:在if语句中定义一个变量
- 23. 在Unix shell中调用控制脚本的子脚本
- 24. 在Python中给定时间运行shell脚本
- 25. shell脚本,子shell,子脚本,管道 - (?)WEIRD CTRL + C信号传播
- 26. Bash Shell脚本:嵌套Select语句
- 27. Shell脚本:RegEx in if语句
- 28. 如果with语句和shell脚本
- 29. Shell脚本。在我的脚本
- 30. 重定向 - Shell脚本