Chinaunix首页 | 论坛 | 博客
  • 博客访问: 953060
  • 博文数量: 113
  • 博客积分: 7235
  • 博客等级: 少将
  • 技术积分: 2101
  • 用 户 组: 普通用户
  • 注册时间: 2008-07-14 11:24
文章分类

全部博文(113)

文章存档

2013年(7)

2012年(5)

2011年(6)

2010年(8)

2009年(15)

2008年(72)

分类: LINUX

2008-07-28 21:14:56

     最近学习linux的内核了,需要经常上去看源代码。有时还写些对某个结构的认识之类的。
   在写的时候,避免不了贴一些源代码在文章中。但直接考下来的代码都含有行号,直接贴上去就像这样:

struct  {
const char * ;
char [];
struct ;
struct ;
struct * ;
struct * ;
struct * ;
struct * ;
;
};

多个行号,看起来很是不爽。看到我们论坛里有人给了删除行号的回答,于是想在这里也可以应用,加以改造,shell脚本如下:
#/bin/sh
if [ -f $1 ]
    then
    sed -s 's/^ *[0-9]\{1,\}//' $1 >.tmp | mv .tmp $1
else
    echo $1
    echo "no input file..."
fi
于是将上面的linux内核代码保存为文件kernel,将该shell脚本保存为del并赋予其可执行权(chmod +x del),在终端下运行:
./del kernel

结果为:
struct kobject {
        const char              * k_name;
        char                    name[KOBJ_NAME_LEN];
        struct kref             kref;
        struct list_head        entry;
        struct kobject          * parent;
        struct kset             * kset;
        struct kobj_type        * ktype;
        struct sysfs_dirent     * sd;
        wait_queue_head_t       poll;
};
直接就将源码每行前面的行号给去掉了。






阅读(2427) | 评论(2) | 转发(0) |
给主人留下些什么吧!~~

xie__6682014-01-12 14:37:14

这个删除行号更好用 http://www.lns7.com/

shinyguo_s2009-10-14 20:23:49

嗯,不错。