• Linux bash sed command All In One


    Linux bash sed command All In One

    sed

    sed, a stream editor

    sed,编辑器

    awk, Perl, gawk

    https://www.gnu.org/software/sed/manual/sed.html

    # sed SCRIPT INPUTFILE...
    
    # to replace all occurrences of ‘hello’ to ‘world’ in the file input.txt:
    
    $ sed 's/hello/world/' input.txt > output.txt
    
    
    # The following commands are equivalent:
    
    $ sed 's/hello/world/' input.txt > output.txt
    
    $ sed 's/hello/world/' < input.txt > output.txt
    
    $ cat input.txt | sed 's/hello/world/' - > output.txt
    

    Linux 命令行编辑器

    sed & gawk

    ???

    vi
    vim
    nano

    emacs

    https://www.gnu.org/software/emacs/

    http://www.hypexr.org/bash_tutorial.php#emacs

    Linux sed 命令

    Linux sed 命令是利用脚本来处理文本文件。

    sed 可依照脚本的指令来处理编辑文本文件。

    Sed 主要用来自动编辑一个或多个文件、简化对文件的反复操作、编写转换程序等。

    # 语法
    $ sed [-hnV][-e<script>][-f<script文件>][文本文件]
    
    

    https://www.runoob.com/linux/linux-comm-sed.html

    https://www.computerhope.com/unix/used.htm

    macOS bug

    $ man sed
    
    $ sed --help
    sed: illegal option -- -
    usage: sed script [-Ealnru] [-i extension] [file ...]
            sed [-Ealnu] [-i extension] [-e script] ... [-f script_file] ... [file ...]
    
    $ sed --version
    sed: illegal option -- -
    usage: sed script [-Ealnru] [-i extension] [file ...]
            sed [-Ealnu] [-i extension] [-e script] ... [-f script_file] ... [file ...]
    
    

    sed API

    参数名称 参数描述
    -e 指定 sed 脚本命令, 多个 sed 命令使用 ; 分隔
    -f 指定 sed 脚本文件 .sed 扩展名
    -n sed 禁用 STDOUT 输出
    # 接受 `STDIN` 作为输入
    $ echo "this is abc" | sed -e 's/abc/xyz/'
    
    $ echo "this is abc" | sed -e 's/abc/xyz/' -n
    

    # 读取文件,返回 `STDOUT` 作为输出
    $ sed -e 's/abc/xyz/' ./test.txt
    
    # ✅ -n filename
    $ sed -e 's/abc/xyz/' -n ./test.txt 
    
    # ❌ filename -n 
    $ sed -e 's/abc/xyz/' ./test.txt -n 
    

    # 多个 sed 命令使用 `;` 分隔, 分号与前面的斜线之间不能有空格 ❓
    $ echo "this is CBA and China" | sed -e 's/CBA/NBA/; s/China/USA/'
    
    # 分号与前面的斜线之间有空格 ✅
    $ echo "this is CBA and China" | sed -e 's/CBA/NBA/ ; s/China/USA/'
    

    # 执行 sed 脚本,sed 后面指定文件名写在命令行里
    $ sed -f test.sed ./test.txt
    
    $ sed -f test.sed ./test.txt >> ./test.out.md
    
    # ✅ -n 
    $ sed -f test.sed  -n ./test.txt
    # ❌ -n
    $ sed -f -n test.sed ./test.txt
    
    # 注释: `.sed`扩展名的文件,是 sed 命令集合专用的,本质上还是一种 shell scirpt
    # 无需写 sed 和 文件名了,因为`.sed`扩展名的文件中是纯 sed 命令
    s/abc//
    s/xyz//
    s/ufo//
    
    
    # 执行 sed 脚本,sed 后面指定文件名写在命令行里
    # $ sed -f test.sed ./test.txt
    # $ sed -f test.sed -n ./test.txt
    # $ sed -f test.sed ./test.txt >> ./test.out.md
    
    # sed: 12: test.sed: invalid command code <
    # <<EOF
    
    # s/abc/xyz/ test.txt
    # sed: 4: test.sed: bad flag in substitute command: 't'
    
    # s/abc/xyz/ ./test.txt
    # sed: 4: test.sed: bad flag in substitute command: '.'
    
    # 's/abc/xyz/' ./test.txt
    # sed: 4: test.sed: invalid command code ' ❌
    
    # sed -e 's/abc/xyz/' ./test.txt
    # sed: 2: test.sed: bad flag in substitute command: 's' ❌
    
    # sed -e 's/abc/xyz/' -n ./test.txt
    
    # EOF
    

    1. 替换 s

    substitute

    
    
    
    
    1. 插入i 和追加 a

    insert / append

    
    
    
    
    1. 删除 d

    delete

    
    
    1. 读取 r

    read

    
    
    1. 写入 w

    write

    
    
    1. 打印 p

    print

    
    

    正则表达式

    
    

    demos

    git hooks

    commit-msg

    #!/bin/sh
    #
    # An example hook script to check the commit log message.
    # Called by "git commit" with one argument, the name of the file
    # that has the commit message.  The hook should exit with non-zero
    # status after issuing an appropriate message if it wants to stop the
    # commit.  The hook is allowed to edit the commit message file.
    #
    # To enable this hook, rename this file to "commit-msg".
    
    # Uncomment the below to add a Signed-off-by line to the message.
    # Doing this in a hook is a bad idea in general, but the prepare-commit-msg
    # hook is more suited to it.
    #
    # SOB=$(git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p')
    # grep -qs "^$SOB" "$1" || echo "$SOB" >> "$1"
    
    # This example catches duplicate Signed-off-by lines.
    
    test "" = "$(grep '^Signed-off-by: ' "$1" |
    	 sort | uniq -c | sed -e '/^[ 	]*1[ 	]/d')" || {
    	echo >&2 Duplicate Signed-off-by lines.
    	exit 1
    }
    
    
    

    XSS

    #!/bin/bash
    
    sed -i "s/xssor.io/$1/g" xssor/payload/probe.js
    
    python3 manage.py runserver 0.0.0.0:8000
    
    

    https://github.com/evilcos/xssor2/blob/master/run.sh

    refs

    https://www.cnblogs.com/xgqfrms/tag/sed

    https://www.cnblogs.com/xgqfrms/p/16243419.html



    ©xgqfrms 2012-2021

    www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!

    原创文章,版权所有©️xgqfrms, 禁止转载 ️,侵权必究⚠️!


  • 相关阅读:
    SSIS ->> Excel Destination无法接受大于255个字符长度的字符字段(转载)
    在express站点中使用ejs模板引擎
    Kali Linux系列教程之OpenVas安装
    Kali Linux Web 渗透测试视频教程— 第二课 google hack 实战
    Kali Linux Web 渗透测试视频教程— 第四课 google hack 实战
    google hack 之 查询语法
    shellKali Linux Web 渗透测试— 初级教程(第三课)
    NODE-WEBKIT教程(12)全屏
    node-webkit教程(11)Platform Service之shell
    node-webkit教程(10)Platform Service之File dialogs
  • 原文地址:https://www.cnblogs.com/xgqfrms/p/16824934.html
Copyright © 2020-2023  润新知