The Gsub function causes the substitution to occur when all regular expressions are matched
Gsub (Regular expression, subsitution string, target string), short gsub (r,s,t)
Sub matches the first occurrence of a conforming pattern string, equivalent to sed ' s//'.
Gsub matches all matching pattern strings, equivalent to sed ' s//g '
Instance One
Remove a number from the second field
echo "0001|20081223efskjfdj| EREADFASDLKJCV "|awk-f ' |" ' Begin{ofs= ' |} {gsub (/[0-9]+/, "", 2);p rint 2);p rint 0} '
0001|efskjfdj| Ereadfasdlkjcv
Example Two
/split, take out the snapshots to know the field between the penultimate fourth (where/the number is not sure, so it is not convenient to directly use awk 6, 6,7,$8 to directly fetch, use the field interception),. Separate com.netfinworks.authorize
Example
/users/yfan/downloads/dsc20170801_jar/snapshots/com/netfinworks/authorize/authorize-service/1.0.0-snapshot/ Authorize-service-1.0.0-snapshot.jar
Set a variable first
Yfandemacbook-pro:pbs yfan$ test=/users/yfan/downloads/dsc20170801_jar/snapshots/com/netfinworks/authorize/ Authorize-service/1.0.0-snapshot/authorize-service-1.0.0-snapshot.jar
Use symbol truncation (# #) in Linux to remove the front part of COM
Yfandemacbook-pro:pbs yfan$ Echo ${test##*snapshots/}
Results
Com/netfinworks/authorize/authorize-service/1.0.0-snapshot/authorize-service-1.0.0-snapshot.jar
In awk, combine gsub to get rid of the back section (penultimate, second, third field)
Yfandemacbook-pro:pbs yfan$ echo ${test##*snapshots/}|awk-f '/' {gsub ("/" $ (NF-2) "/" $ (NF-1) "/" $NF, "");p rint} '
Results
Com/netfinworks/authorize
Finally, use SED. To replace/to accomplish a goal
Yfandemacbook-pro:pbs yfan$ echo ${test##*snapshots/}|awk-f '/' {gsub ("/" $ (NF-2) "/" $ (NF-1) "/" $NF, "");p rint} ' |sed ' s/\//./g '
Results
Com.netfinworks.authorize
Gsub Description Reference:
Http://blog.sina.com.cn/s/blog_67e34ceb0100ybvg.html