gpt4 book ai didi

regex - 如何用 sed 替换一行/

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:36:25 25 4
gpt4 key购买 nike

您好,我目前有一个这种格式的文件:

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

关于regex - 如何用 sed 替换一行/,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30062739/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com