learn Linux sed command

简介: learn Linux sed command 一、参考文档: 1. sed命令详解 http://qifuguang.
                                  learn Linux sed command


一、参考文档:
    1. sed命令详解
        http://qifuguang.me/2015/09/21/sed%E5%91%BD%E4%BB%A4%E8%AF%A6%E8%A7%A3/
    2. linux之sed用法
        http://www.cnblogs.com/dong008259/archive/2011/12/07/2279897.html
    3. Sed 的man手册参数详细解释(一)
        http://blog.csdn.net/imfinger/article/details/6071175

二、sed命令的使用规则是这样的:
    sed [option] 'command' input_file

三、options:
    -n, --quiet, --silent
        suppress automatic printing of pattern space
    -e script, --expression=script
        add the script to the commands to be executed
        如果命令行上只有一个指令的时候可以不用写-e,但是如果有多个指令的话一定要在每个指令的前面加-e选项。
    -f script-file, --file=script-file
        add the contents of script-file to the commands to be executed
        这里貌似是前面对应的-e对应的脚本
    --follow-symlinks
        follow symlinks when processing in place
    -i[SUFFIX], --in-place[=SUFFIX]
        edit files in place (makes backup if extension supplied)
    -l N, --line-length=N
        specify the desired line-wrap length for the `l' command
    --posix
        disable all GNU extensions.
    -r, --regexp-extended
        use extended regular expressions in the script.
    -s, --separate
        consider  files  as  separate rather than as a single continuous
        long stream.
    -u, --unbuffered
        load minimal amounts of data from the input files and flush  the
        output buffers more often
    --help
        display this help and exit
    --version
        output version information and exit

四、command有以下几种:
    a \: append即追加字符串, a \的后面跟上字符串s(多行字符串可以用\n分隔),则会在当前选择的行的后面都加上字符串s;
    c \: 取代/替换字符串,c \后面跟上字符串s(多行字符串可以用\n分隔),则会将当前选中的行替换成字符串s;
    d  : delete即删除,该命令会将当前选中的行删除;
    i \: insert即插入字符串,i \后面跟上字符串s(多行字符串可以用\n分隔),则会在当前选中的行的前面都插入字符串s;
    p  : print即打印,该命令会打印当前选择的行到屏幕上;
    s  : 替换,通常s命令的用法是这样的:1,2s/old/new/g,将old字符串替换成new字符串

 

目录
相关文章
|
Linux Perl
一个神奇的Linux命令-sed
一个神奇的Linux命令-sed
135 1
|
存储 监控 Linux
性能工具之linux三剑客awk、grep、sed详解
Linux 三剑客 awk,sed和grep 在性能领域广泛用于性能建模、性能监控及性能分析等方面,也是各大互联网公司测试岗高频面试题,中高端测试人员必备技能之一。
527 1
性能工具之linux三剑客awk、grep、sed详解
|
Linux Perl
在Linux中,如何使用请用 cut 或者 awk,sed命令取出 linux 中 eth0 的 IP 地址?
在Linux中,如何使用请用 cut 或者 awk,sed命令取出 linux 中 eth0 的 IP 地址?
|
机器学习/深度学习 Linux Perl
Linux文本处理三剑客之sed详解
这篇博客详细讲解了Linux中的文本处理工具sed的使用方法和常用命令。
853 9
Linux文本处理三剑客之sed详解
|
Linux Perl
Linux之sed命令
Linux之sed命令
|
人工智能 监控 Shell
常用的 55 个 Linux Shell 脚本(包括基础案例、文件操作、实用工具、图形化、sed、gawk)
这篇文章提供了55个常用的Linux Shell脚本实例,涵盖基础案例、文件操作、实用工具、图形化界面及sed、gawk的使用。
4121 2
|
Linux Shell Perl
在Linux中,如何使用sed命令进行文本替换?
在Linux中,如何使用sed命令进行文本替换?
|
Linux Perl
6-20|linux sed命令
6-20|linux sed命令
|
存储 Linux BI
Linux 三剑客 grep、sed、awk
Linux三剑客`grep`、`sed`和`awk`是强大的文本处理工具。`grep`用正则表达式搜索匹配行;`sed`是流式编辑器,处理文本流而不直接修改原文件;`awk`则用于灵活的文本分析和报告生成。例如,`grep`可查找匹配模式,`sed`可以删除文件内容,而`awk`能提取特定字段。通过组合使用,它们能高效解决复杂文本任务。
747 1
|
Shell Linux Perl
Linux shell脚本sed使用
Linux shell脚本sed使用
157 1