我只想獲得字符串 new-profile-input 的一部分,我需要的部分是:沒有“-input”的“new-profile”。
我試過這樣:
cat automatization_test.sh | grep -oh "\new-profile-input\w*" | grep -o "\-input\w*"
但是,我得到輸出:
-輸入
但是,我需要字符串的第一部分而不是最後一部分。請注意“new-profile”總是會改變,所以這就是為什麼我必須專注於刪除“-input”而不是只獲取“new-profile”。
先感謝您,
使用sed
,您可以排除示例字符串中最後一個-
斜杠之後的所有內容-input
。
$ sed 's/\(.*\)-.*/\1/' automatization_test.sh
new-profile
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句