删除第一行/包括第一行/每行之后的所有内容 [英] Remove everything after the first / including the first / for each line
本文介绍了删除第一行/包括第一行/每行之后的所有内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个包含很多主机名的文件.有些在我想删除的主机后面有一个 url 部分.换句话说:
I have a file with lots of host names. Some have a url part after the host that I'd like to remove. In other words:
google.com
facebook.com
acme.com/news/frontpage
bbc.co.uk
abc.com/home/index
应该变成
google.com
facebook.com
acme.com
bbc.co.uk
abc.com
推荐答案
一种方式:
sed 's|/.*||' file
结果:
google.com
facebook.com
acme.com
bbc.co.uk
abc.com
您可能想阅读更多有关使用斜杠作为分隔符的信息.哈.
You may want to read more about using the slash as a delimiter. HTH.
这篇关于删除第一行/包括第一行/每行之后的所有内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文