文本处理工具学习-sed系列之二

    sed的常用选项以及命令大致就是这些了,以后用到其它选项和相关的命令我会续上,敬请期待!

    接下来我就这些常用选项和命令举一些例子,注意:这些例子仅供参考,如有雷同纯属巧合,哈哈。

    (1)p 代表打印匹配行

            

            [root@test2 tmp]# cat test1.txt 

                138569606060

                fjswkkflofglfl

                cjhed838jsdiso

                fjeois9cdo9do

            [root@test2 tmp]# sed "p" test1.txt 

                138569606060

                138569606060

                fjswkkflofglfl

                fjswkkflofglfl

                cjhed838jsdiso

                cjhed838jsdiso

                fjeois9cdo9do

                fjeois9cdo9do

            [root@test2 tmp]# sed "1p" test1.txt 

                138569606060

                138569606060

                fjswkkflofglfl

                cjhed838jsdiso

                fjeois9cdo9do

            [root@test2 tmp]# sed "2p" test1.txt

                138569606060

                fjswkkflofglfl

                fjswkkflofglfl

                cjhed838jsdiso

                fjeois9cdo9do


            [root@test2 tmp]# sed "1,2p" test1.txt 

                138569606060

                138569606060

                fjswkkflofglfl

                fjswkkflofglfl

                cjhed838jsdiso

                fjeois9cdo9do

            [root@test2 tmp]# sed "1,3p" test1.txt 

                138569606060

                138569606060

                fjswkkflofglfl

                fjswkkflofglfl

                cjhed838jsdiso

                cjhed838jsdiso

                fjeois9cdo9do

    

            [root@test2 tmp]# sed -e "1p" -e "3p" test1.txt 

                138569606060

                138569606060

                fjswkkflofglfl

                cjhed838jsdiso

                cjhed838jsdiso

                fjeois9cdo9do

            [root@test2 tmp]# sed "1p;3p" test1.txt 

                138569606060

                138569606060

                fjswkkflofglfl

                cjhed838jsdiso

                cjhed838jsdiso

                fjeois9cdo9do

            [root@test2 tmp]# sed -n "/^f/p" test1.txt 

                fjswkkflofglfl

                fjeois9cdo9do

未完待续......


你可能感兴趣的:(linux运维,shell脚本,文本处理工具)