这是我的输入行
[[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/