sed

Linux下的sed流编辑器命令详解

孤者浪人 提交于 2020-03-05 12:39:27
命令示例: [root@master rh]# cat test.txt this is first line this is second line this is third line this is fourth line this fifth line happy everyday end a 命令 sed '1a \add one' test.txt 本例命令部分中的1表示第一行,同样的第二行写成2,第一行到第三行写成1,3,用$表示最后一行,比如2,$表示第二行到最后一行中间所有的行(包含第二行和最后一行)。 本例的作用是在第一行之后增加字符串”add one”,从输出可以看到具体效果。 sed '1,$a \add one' test.txt 本例表示在第一行和最后一行所有的行后面都加上”add one”字符串,从输出可以看到效果。 sed '/first/a \add one' test.txt 本例表示在包含”first”字符串的行的后面加上字符串”add one”,从输出可以看到第一行包含first,所以第一行之后增加了”add one” sed '/^ha.*day$/a \add one' test.txt 本例使用正则表达式匹配行,^ha.*day$表示以ha开头,以day结尾的行,则可以匹配到文件的”happy everyday”这样

search in output and cat from specific line to specific line and search again

半城伤御伤魂 提交于 2020-03-05 05:34:10
问题 I wrote something like: OUT=$( nmap -p "$port" --script=http-headers.nse "$ip" for example the output is: |http-headers: | Server: Apache | Vary: Accept-Encoding | Content-Type: text/html; charset=utf-8 | Date: Thu, 06 Feb 2014 07:31:33 GMT | Age: 25 | Connection: close but the length of my output is changeable. so I want something to search between lines in my output (better to use sed or awk ) and check a condition. for example if it sees Apache from line 3 till line 8 then echo right Edit:

Linux之特殊符号与正则表达式

吃可爱长大的小学妹 提交于 2020-03-04 12:21:34
Linux中常用的特殊符号 '' 所见即所得,吃啥吐啥 "" 特殊符号会被解析运行 `` ==== $() 先运行里面的命令 把结果留下 > 重定向符号 先清空文件的内容 然后追加文件的最后 >> 追加重定向 追加文件的最后 2> 错误重定向 只有错误的信息 才会通过这个漏洞进入文件中 2>> 错误追加重定向 ~ 当前用户的家目录 root ~ /root oldboy ~ /home/oldboy ! 查找并运行历史命令 !awk 包含awk的命令 最近的一条运行 history |grep awk # 注释 root用户的命令提示符 $ 取出变量的内容 awk $取某一列的内容 普通用户的命令提示符 * 所有 任何东西 \ 撬棍 转义字符 && 前一个命令执行成功然后在执行后一个命令 ifdown eth0 && ifup eth0 || 前一个命令支持失败了再执行后面的命令 通配符 通配符是用来查找文件的。如:‘*.txt’ 表示匹配所有以 . txt结尾的文件##1. * 所有,任意 找出文件名包含oldboy的文件 mkdir -p /oldboy cd /oldboy touch oldboy.txt oldboy oldboyfile oldboy.awk eduoldboy [root@oldboyedu01-nb oldboy]# find /oldboy/

扩展正则表达式及应用

折月煮酒 提交于 2020-03-04 06:21:40
第1章 扩展正则表达式 1.1 + 前一个字符连续出现了 1 次或 1 次以上 egrep "0+" clsn.txt 1 次或 1 次以上 >=1 egrep "0*" clsn.txt 0 次或 0 次以上 >=0 1.1.1 找到文本中的 0 [root@znix ~]# egrep "0+" clsn.txt my qq num is 49000448. not 4900000448. [root@znix ~]# egrep -o "0+" clsn.txt 000 00000 1.1.2 取出文件中的大写字母 [root@znix ~]# grep -o "[A-Z]" clsn.txt I I I O L D B O Y 1.1.3 取出连续出现的大写字母 [root@znix ~]# egrep -o "[A-Z]+" clsn.txt I I I clsn 1.1.4 显示所有的单词 [root@znix ~]# egrep -o "[A-Za-z]+" clsn.txt I am clsn teacher 1.2 | 或者 表示找其中的一个或者是另外一个。 [root@znix ~]# egrep "clsn|oldbey" clsn.txt -o clsn clsn oldbey 找 /etc/services 中的两个端口 [root@znix ~]#

jquery模拟生日日期下拉选择框

僤鯓⒐⒋嵵緔 提交于 2020-03-03 11:14:11
现在有很多关于日期的插件,但是都是年、月、日以日历的形式出现,我在项目有需求是日期以下拉框的形式完成。如图: //HTML代码如下;       <div class="phone_mation"> <div class="weui-cell__hd" id="birth"> <label class="weui-label"><span>* </span>生日</label> <div class="birth-r"> <div class="year"> <select id="date-sel-year" rel="1985" class="cx_nd"></select> </div> <div class="year"> <select id="date-sel-month" rel="10" class="cx_nd"></select> </div> <div class="year"> <select id="date-sel-day" rel="01" class="cx_nd"></select> </div> </div> </div> </div> //需要引入插件: // 出生年月插件 $.date_picker({ YearSelector: "#date-sel-year", MonthSelector: "#date-sel-month",

Sed error “\1 not defined in the RE” on MacOSX 10.9.5

眉间皱痕 提交于 2020-03-03 06:07:33
问题 I am trying to build a generic formatter for my MP3 file names (very important) with bash, and a large part of this is being able to move text around using regex variables. For example I am trying to remove the parentheses () from around the ft. Kevin Parker. oldfilename="Mark Ronson - 02 Summer Breaking (ft. Kevin Parker).mp3" newfilename=$(echo $oldfilename | sed -E "s/ft.\(*\)/ft.\1/g") This causes the error: sed: 1: "s/ft.\(*\)/gt.\1/g": \1 not defined in the RE I have tried escaping and

Sed error “\1 not defined in the RE” on MacOSX 10.9.5

随声附和 提交于 2020-03-03 06:07:24
问题 I am trying to build a generic formatter for my MP3 file names (very important) with bash, and a large part of this is being able to move text around using regex variables. For example I am trying to remove the parentheses () from around the ft. Kevin Parker. oldfilename="Mark Ronson - 02 Summer Breaking (ft. Kevin Parker).mp3" newfilename=$(echo $oldfilename | sed -E "s/ft.\(*\)/ft.\1/g") This causes the error: sed: 1: "s/ft.\(*\)/gt.\1/g": \1 not defined in the RE I have tried escaping and

【Linux学习记录 D:03】——使用Linux命令进行Excel表格的插入

二次信任 提交于 2020-03-03 01:42:55
文章目录 简介 准备 过程 将xlsx文件更改成zip文件,并解压至unziptable目录下 通过Excel表格中已有的学生姓名匹配出xuehao.txt文件中的学生学号,并插入至Excel表格中 将所有解压的内容压缩 将压缩的table2.zip 更改为xlsx文件 结果 简介 使用Linux命令:sed、grep、zip、unzip进行控制Excel表格进行插入操作的整理记录 准备 一份学生学号文件 一份关于学生的Excel文件 过程 将xlsx文件更改成zip文件,并解压至unziptable目录下 unzip 命令 -d<目录> 指定文件解压缩后所要存储的目录。 [root@dst excel2] # mv table.xlsx table.zip [root@dst excel2] # unzip table.zip -d unziptable 通过Excel表格中已有的学生姓名匹配出xuehao.txt文件中的学生学号,并插入至Excel表格中 Excel表格中学生所在的单元格 #1.查找学生姓名 grep Sheet1 . B . . . . . . . . . . . . . . . . . unziptable/ * - R - o | #2.进行清洗 sed 's/.*f><v>//g' | sed 's/<.*//g' | #3

[100]第三波常用命令

梦想的初衷 提交于 2020-03-02 08:19:29
用到的时候措手不及,不用的时候一大坨. 基于这个原因,打算重整旗鼓,经常用到的命令和栗子整理如下 像是割草一样,我不信搞不彻底.搞不顺手. find+xargs/sed&sed后向引用+awk多匹配符+过滤行绝招总结&&产生随机数 sort-uniq awk运算-解决企业统计pv/ip问题 1.mkdir 2.ls -l -d 显示目录 -F 给文件夹结尾加/标识 -a 以.开头的都是隐藏文件 -rt 按照修改时间倒序排列(最新修改的在最下) ls -lrth 3.cd 4.pwd 5.touch 6.vi 7.vim 8.echo 配合 > >> -n 不换行 -e 内容携带转义(\n回车 \t tab) - 不换行 [root@n6 ~]# echo -n '123' 123[root@n6 ~]# - 让\n等转义 默认是: [root@n6 ~]# echo 'mao\ntai' mao\ntai 加-e后 [root@n6 ~]# echo -e 'mao\ntai' mao tai 9.cat -n 显示行号 10.xargs: http://man.linuxde.net/xargs -n max-args 多少个一组,默认是1 -i [replace-str] 后向引用 - 用法展示 echo stu{1..20}|xargs -n 2 > 2.md - 单行输出

linux基础命令二

爱⌒轻易说出口 提交于 2020-03-02 06:44:15
一、grep grep:过滤 参数-v 排除 grep -v old aaa.txt 在aaa.txt中排除old字符串所在的行 grep old aaa.txt 只显示包含old的行 -E 参数,可过滤多个字符串,用""括起来,用|分隔开 。等同于egrep grep -E "d|e" 1.txt 将文件中的d和e所在的行显示出来,等同于egrep "d|e" 1.txt grep -Ev "d|e" 1.txt 将文件中的d和e所在的行不显示,-v过滤掉 二、head、tail head -n 文件 :显示文件的前n行 tail -n 文件 : 显示文件的后n行 head和tail两个命令,如果不加-n参数则默认显示前10行或后10行 三、三剑客sed\awk\grep sed:取各种内容、按行处理 sed /old/p aaa.txt 将包含old的内容打印出来,同时整个文件的内容打印一遍。其中p表示打印 sed -n /old/p aaa.txt 将包含old的行打印出来,同时过滤掉原始内容,即只打印要查询的,等同与grep old aaa.txt sed /old/d aaa.txt 将包含old的行删除(假删除),其他内容打印。d参数时删除的意思,等同于grep -v old aaa.txt 总结:-n表示取消默认输出 p打印 d删除 sed -n 20,30p aaa