简体   繁体   English

移除 url 的一部分并使用 sed 保留 rest

[英]Remove part of url and keep the rest using sed

Need to remove some part of the url and keep the remaining part same.需要删除 url 的某些部分并保持其余部分相同。 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"
}

from above two urls i want get rid off nxt- and keep the rest.从以上两个网址我想摆脱nxt-并保留 rest。 I know using我知道使用

sed -i 's/nxt-//g' FILE

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.可以解决这个问题,但我想具体一点,只删除第一个 url 的 nxt- 和第二个 url 的 nxt- 而不更改文件的 Z65E8800B5C6800AAD896F888B2A62A。

I am trying this我正在尝试这个

sed -i '/host/s#"http://nxt-newepisode.*"#" "#' FILE

Could you please try following.请您尝试以下操作。

awk '/host/ && ++count==1{sub(/nxt-/,"")} 1' Input_file

Once you are happy with results then to save output into Input_file use following:一旦您对结果感到满意,然后将 output 保存到 Input_file 中,请使用以下命令:

awk '/host/ && ++count==1{sub(/nxt-/,"")} 1' Input_file > temp && mv temp Input_file

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM