bash - 如何删除字符串bash shell中第n次出现的字符

标签 bash shell

我有这样一个字符串:str="test,test,test,test,test,test"。如何删除字符串 str 中的第 n 个逗号 (,),其中 n 介于 15 之间? 任何人都可以提出任何建议吗?谢谢。

最佳答案

$ echo "$str"
test,test,test,test,test,test
$ sed 's/,//5' <<<"$str" #or echo "$str" |sed 's/,//5'
test,test,test,test,testtest

关于bash - 如何删除字符串bash shell中第n次出现的字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45746141/

相关文章:

linux - 如何在 Unix 命令行上定位用户

regex - 使用 grep 等 bash 工具解决难题

linux - 在 bash 脚本中删除基于名称作为日期的文件夹在 mm/dd/yy 中

bash - 如何在使用 Plink 执行的 bash 文件中接受用户输入?

macos - 单击 growl 通知启动应用程序

bash - 加速从文件中读取 sed 替换字符串

linux - 最后创建的远程文件上的 Bash cat

mysql - 在 bash 和 mysql 中使用反斜杠

linux - 狂欢 : Search Contents of File A in File B and Print lines of File A in File C

bash - 如何使用 sed 或 awk 在模式后删除某些字符?