使用sed:
sed -E 's/.*\/(.*)-.*/\1/' plainlinks
999999-94092
999999-94094
999999-94096
999999-94097
999999-94098
999999-94644
999999-94645
999999-94995
999999-94996
999999-96404
要将更改保存到文件,请使用-i选项:
sed -Ei 's/.*\/(.*)-.*/\1/' plainlinks
或者保存到新文件然后重定向:
sed -E 's/.*\/(.*)-.*/\1/' plainlinks > newfile.txt
说明:
s/ # subsitution
.* # match anything
\/ # upto the last forward-slash (escaped to not confused a sed)
(.*) # anything after the last forward-slash (captured in brackets)
- # upto a hypen
.* # anything else left on line
/ # end match; start replace
\1 # the value captured in the first (only) set of brackets
/ # end