日期:2014-05-16  浏览次数:20616 次

用shell脚本,删除文件开头的一部分东西。
怎么用shell脚本把一个文件的前面部分删掉。
比如我想删掉下面我给出的数据。
可以用 sed '1,17d'来删除1 到 17行,
但是现在是 17 这个数是未知的。只知道要删除到第一个 <item> (第17行)。
有什么方法吗,最好不要写一堆脚本来找这个 <item>的行号, 最好有比较少的脚本代码。


<?xml version='1.0' encoding='utf-8'?>
<?xml-stylesheet type='text/css' href='http://news.sohu.com/rss/rss.css'?>
<rss version="2.0">
    <channel>
        <title>新闻中心</title>
        <image>
            <title>www.sohu.com</title>
            <link>http://www.sohu.com</link>
            <url>http://images.sohu.com/logo1.gif</url>
        </image>
        <description>快捷、海量、权威;为广大网友提供全球新闻信息</description>
        <link>http://news.sohu.com/</link>
        <language>zh-cn</language>
        <docs>http://news.sohu.com/</docs>
        <generator>www.sohu.com</generator>
        <ttl>5</ttl>
        <item>
        .....
        下面还有很多东西。
------解决方案--------------------
引用
但是现在是 17 这个数是未知的。只知道要删除到第一个 <item> (第17行)。


sed '0,/<item>/d' urfile