AWK/SED如何将骆驼网址路径更改为下划线路径? [英] Awk/Sed how to change a camel url path to a underscore path?
本文介绍了AWK/SED如何将骆驼网址路径更改为下划线路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下文字:
SendNoticeMsg (api.post = "/test/SendNoticeMsg")
我想将文本更改为:
SendNoticeMsg (api.post = "/test/send_notice_msg")
我尝试使用此sed脚本:
I tried to use this sed script:
sed -E 's/(\/test\/.*)([A-Z]).*\"/\1\2_\L/'
但这是行不通的.
推荐答案
使用GNU awk将第三个参数匹配():
With GNU awk for the 3rd arg to match():
awk 'match($0,"(.*/test/)(.)(.*)",a){ gsub(/[[:upper:]]/,"_&",a[3]); $0=a[1] tolower(a[2] a[3]) } 1' file
SendNoticeMsg (api.post = "/test/send_notice_msg")
这篇关于AWK/SED如何将骆驼网址路径更改为下划线路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文