-1
A
回答
0
你不需要SED。 Bash parameter expansion會做:
$ Short_name="This_is_test_string"
$ echo "${Short_name##*_is_}"
test_string
從字符串的開頭刪除所有內容幷包括最後「_is_」
1
像這樣:
echo 'Short_name="This_is_test_string"' | sed 's/.*_is_//;s/"//'
其分解:
s -- substitute command
/ -- delimiter
.*_is_ -- match this
.* -- any character (.), as many as possible (*)
_is_ -- these 4 exact characters
/ -- delimiter
(nothing) -- what to replace any match with
/ -- delimiter
; -- end this command, start another
s -- substitute command
/ -- delimiter
" -- match this character
/ -- delimiter
(nothing) -- what to replace any match with
/ -- delimiter
[編輯]
的關鍵是搞清楚哪些模式符合您的需求(我還沒有很好的下站立)。也許是這樣的:
... | sed 's/.*[[:<:]]is[ _]*//;s/"//'
的「刁鑽位」這裏是[[:<:]]
這是一個「零寬度斷言」(在這種情況下「字的開始」),這使我們做的這樣的輸入錯誤的事情:
echo 'string2=is this it"' | sed 's/.*[[:<:]]is[ _]*//;s/"//'
(通過保持我們從匹配 「是」,在 「本」)
相關問題
- 1. 使用sed刪除具有通用前綴的單詞
- 2. 刪除單詞用的sed
- 3. 刪除unix中兩個單詞之間的字符串
- 4. 使用binarySearch從ArrayList中刪除單詞
- 5. 刪除單詞,如果替代單詞已在excel中使用
- 6. 刪除DocumentTermMatrix中的單詞
- 7. 如何在UNIX中從文件中刪除單詞?
- 8. 用於刪除單詞的VBA代碼
- 9. 刪除用戶從單詞列表中選擇的單詞
- 10. Eclipse刪除單詞行爲
- 11. 刪除單詞換行
- 12. php刪除單詞開頭#
- 13. 從NSString中刪除單詞
- 14. 如何使用sed/awk刪除具有多個模式計數的單詞
- 15. Git刪除具體提交
- 16. 如何在單詞超過2億時使用Java刪除重複的單詞?
- 17. Python Openpyxl ...刪除具有特定單詞的行
- 18. 用Jquery和Regex刪除單詞
- 19. 使用bash在Unix中刪除文件
- 20. 刪除停用詞
- 21. 刪除禁用詞
- 22. 單詞粗體和刪除的Vba代碼
- 23. 如何使用javascript或jquery刪除/刪除第一個空格的單詞?
- 24. 從unix中的文本文件中計算單詞和刪除字符串
- 25. 使用unix shell腳本從文件中刪除單行
- 26. Unix刪除文件
- 27. 刪除單詞文檔中重複的相鄰單詞
- 28. R gsub從列x中的單詞中刪除單詞y
- 29. 記事本++刪除所有不在單詞表中的單詞
- 30. 刪除特定單詞後的兩個單詞
你是說你有一個名爲'Short_name',其值是'變量」 This_is_test_string「'或一個變量的值是'Short_name =」This_is_test_string「'或其他?你爲什麼需要使用sed? –