gpt4 book ai didi

linux - 如何在 shell 脚本中交换单词?

转载 作者:太空宇宙 更新时间:2023-11-04 09:54:01 28 4
gpt4 key购买 nike

这是我的输入行
[[ref:start|其他配置文件、程序和脚本]]

我需要将上面的行转换成
"其他配置文件、程序和脚本":ref/start

如何使用 sed 命令转换它?

最佳答案

写比读容易:)

$ echo "[[ref:start|Other config files, programs, and scripts]]" |\
sed 's/\[\[\([^:]*\):\([^|]*\)|\(.*\)\]\]/"\3":\1\/\2/'
"Other config files, programs, and scripts":ref/start

我建议您阅读 man sed以及GNU sed manual .它不是那么大,您实际上不需要一次阅读所有内容。在大多数情况下,了解 s/// 命令、正则表达式语法和 sed 的标志就足够了(最有用的是 -n-i) .

关于linux - 如何在 shell 脚本中交换单词?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7695156/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com