Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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"
}

from above two urls i want get rid off nxt- and keep the 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.

I am trying this

sed -i '/host/s#"http://nxt-newepisode.*"#" "#' FILE
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
226 views
Welcome To Ask or Share your Answers For Others

1 Answer

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:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...