[英]How do I replace a line with sed with /
您好,我目前有一個這種格式的文件:
This is a test file
location = /home/files
我的問題是如何用此location = /home/documents/test_files
替換此location = /home/files
?
當原始字符串或替換字符串中有一個“ /”時,我們考慮使用“ \\”對“ /”進行轉義。 另外,您可以使用任何字符作為替換定界符,例如“ @”
$ cat sample.csv
This is a test file
location = /home/files
$ sed 's@/home/files@/home/documents/test_files@' sample.csv
This is a test file
location = /home/documents/test_files
只需選擇其他定界符即可:
sed 's-location = /home/files-location = /home/documents/test_files-' test.txt
sed 's~location = /home/files~location = /home/documents/test_files~' test.txt
或轉義/
:
sed 's/location = \/home\/files/location = \/home\/documents\/test_files/' test.txt
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.