有没有办法给单词加上正斜杠?像这样
测试-> / test /
我有这个文件,
switch1 Ethernet13 1 4 5
switch1 Ethernet14 1 4 5
switch1 Ethernet15 1 4 5
switch1 Ethernet8 1 4 5
switch1 Ethernet16 1 4 5
switch1 Ethernet1 2002 2697 2523
switch1 Ethernet17 2002 2576 2515 想把它改成这样,
/switch1/ /Ethernet13/ /1/ /4/ /5/
/switch1/ /Ethernet14/ /1/ /4/ /5/
/switch1/ /Ethernet15/ /1/ /4/ /5/
/switch1/ /Ethernet8/ /1/ /4/ /5/
/switch1/ /Ethernet16/ /1/ /4/ /5/
/switch1/ /Ethernet1/ /2002/ /2697/ /2523/
/switch1/ /Ethernet17/ /2002/ /2576/ /2515/ 我之所以寻找这种类型的格式,是因为我可以在awk中使用它来查找匹配的模式。我试过了,但它只打印了0(零)输出,
awk '{print "\/$1\/}' 感谢您的任何想法或建议。
发布于 2014-05-29 07:06:35
我将使用以下sed命令:
sed 's~\([^ \t]\+\)~/\1/~g' file.txt它用斜杠将所有非空格字符组([^ \t]\+)括起来。
发布于 2014-05-29 07:39:40
您可以使用以下代码。
sed -r 's!(\S+)!/\1/!g' file.txt发布于 2014-05-29 07:53:16
如果你的awk有gensub()功能...
awk '{ print gensub(/(\w+)/, "/\\1/", "g") }' file.txt关于gensub
gensub(regexp, replacement, how [, target]) #
gensub()是一个通用的替代函数...比标准的sub()和gsub()函数有更多的特性...能够在替换文本中指定正则表达式的组件
https://stackoverflow.com/questions/23923266
复制相似问题