删除部分 url 并使用 sed 保留其余部分 [英] Remove part of url and keep the rest using sed
本文介绍了删除部分 url 并使用 sed 保留其余部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
需要删除一部分 url 并保持其余部分相同.下面是我的文本文件的一部分,其中包含这样的
Need to remove some part of the url and keep the remaining part same . Below is the part of my text file which contains like this
{
host = "http://nxt-newepisode.xcfm.crata.dive.com/err1.2.2/table/kenny.xml.gz"
}
{
host = "http://nxt-secondepisode.xcfm.crata.dive.com/err1.2.2/table/kenny.xml.gz"
}
从上面两个网址我想摆脱 nxt- 并保留其余的.我知道使用
from above two urls i want get rid off nxt- and keep the rest . I know using
sed -i 's/nxt-//g' FILE
可以解决这个问题,但我想具体一点,只删除第一个 url 的 nxt- 和第二个 url 的 nxt- 而不更改文件的其余部分.
can solve the issue but i want to be specific and only remove nxt- for first url and nxt- from second url without making changes to rest of file.
我正在尝试这个
sed -i '/host/s#"http://nxt-newepisode.*"#" "#' FILE
推荐答案
你可以试试看吗.
awk '/host/ && ++count==1{sub(/nxt-/,"")} 1' Input_file
一旦您对结果感到满意,然后将输出保存到 Input_file 中,请使用以下内容:
Once you are happy with results then to save output into Input_file use following:
awk '/host/ && ++count==1{sub(/nxt-/,"")} 1' Input_file > temp && mv temp Input_file
这篇关于删除部分 url 并使用 sed 保留其余部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文