sed

sed (in bash) works with [ \t] but not with \s?

£可爱£侵袭症+ 提交于 2020-02-21 12:58:32
问题 I want to search-replace something containing whitespace on a bash command line, and I assumed sed would be the easiest way to go. Using [ \t] denoting either tab or space, to match the whitespace, works as intended: echo "abc xyz" | sed "s/[ \t]xyz/123/" abc123 But using \s instead of [ \t] does not, to my surprise: echo "abc xyz" | sed "s/\sxyz/123/" abc xyz I'm fairly new to bash so I might be missing something trivial, but no matter what I do, I can't get this to work. Using \\s instead

sed (in bash) works with [ \t] but not with \s?

我们两清 提交于 2020-02-21 12:57:42
问题 I want to search-replace something containing whitespace on a bash command line, and I assumed sed would be the easiest way to go. Using [ \t] denoting either tab or space, to match the whitespace, works as intended: echo "abc xyz" | sed "s/[ \t]xyz/123/" abc123 But using \s instead of [ \t] does not, to my surprise: echo "abc xyz" | sed "s/\sxyz/123/" abc xyz I'm fairly new to bash so I might be missing something trivial, but no matter what I do, I can't get this to work. Using \\s instead

sed (in bash) works with [ \t] but not with \s?

假如想象 提交于 2020-02-21 12:57:09
问题 I want to search-replace something containing whitespace on a bash command line, and I assumed sed would be the easiest way to go. Using [ \t] denoting either tab or space, to match the whitespace, works as intended: echo "abc xyz" | sed "s/[ \t]xyz/123/" abc123 But using \s instead of [ \t] does not, to my surprise: echo "abc xyz" | sed "s/\sxyz/123/" abc xyz I'm fairly new to bash so I might be missing something trivial, but no matter what I do, I can't get this to work. Using \\s instead

sed 命令

白昼怎懂夜的黑 提交于 2020-02-21 10:21:29
sed命令详解 2015-09-21 常识积累 热度4175℃ 2条评论 概述 sed是stream editor的简称,也就是流编辑器。它一次处理一行内容,处理时,把当前处理的行存储在临时缓冲区中,称为“模式空间”(pattern space),接着用sed命令处理缓冲区中的内容,处理完成后,把缓冲区的内容送往屏幕。接着处理下一行,这样不断重复,直到文件末尾。文件内容并没有 改变,除非你使用重定向存储输出。 使用语法 sed命令的使用规则是这样的: 1 sed [option] 'command' input_file 其中option是可选的,常用的option有如下几种: -n 使用安静(silent)模式(想不通为什么不是-s)。在一般sed的用法中,所有来自stdin的内容一般都会被列出到屏幕上。但如果加上-n参数后,则只有经过sed特殊处理的那一行(或者动作)才会被列出来; -e 直接在指令列模式上进行 sed 的动作编辑; -f 直接将 sed 的动作写在一个文件内, -f filename 则可以执行filename内的sed命令; -r 让sed命令支持扩展的正则表达式(默认是基础正则表达式); -i 直接修改读取的文件内容,而不是由屏幕输出。 常用的命令有以下几种: a \: append即追加字符串, a \的后面跟上字符串s(多行字符串可以用\n分隔)

Sed on Mac not recognizing regular expressions

我是研究僧i 提交于 2020-02-21 06:10:31
问题 In terminal, I am attempting to clean up some .txt files so they can be imported into another program. Only literal search/replaces seem to be working. I cannot get regular expression searches to work. If I attempt a search and replace with a literal string, it works: find . -type f -name '*.txt' -exec sed -i '' s/Title Page// {} +; (remove the words "Title Page" from every text file) But if I am attempting even the most basic of regular expressions, it does not work: find . -type f -name '*

grep/sed/awk命令查看指定时间段的日志

╄→尐↘猪︶ㄣ 提交于 2020-02-19 17:19:53
*grep命令 今天遇到研发要求查询定时任务(elastic-job)在14:00-14:40的日志,使用grep命令很方便: 命令: grep '时间' '日志文件名 ' 1、例如查询2020-02-19 14:10到2020-02-19 14:15区间的日志 grep "2020-02-19 14:1[0-5]" dubbo-elastic-job.log 查询日志时间正好截至2020 02-19 14:15 2、例如查询当天10点到11点的日志 grep "2020-02-19 1[0-1] " dubbo-elastic-job.log *sed命令---推荐使用   1、例如查询2020-02-19 14:10到2020-02-19 14:15区间的日志 sed -n '/2020-02-19 14:10:00/,/2020-02-19 14:15:00/p' dubbo-elastic-job.log *awk命令   1、例如查询今天14:10:10 到14:12:59区间的日志,注意时间要用引号 awk '$2>"14:10:10" && $2<"14:12:59"' dubbo-elastic-job.log   注意参数$1和$2的取值,我这里$1是指年月日,$2是指时分秒。    来源: https://www.cnblogs.com/python-wen/p

Python学习Day09-Linux初识

╄→尐↘猪︶ㄣ 提交于 2020-02-19 10:53:47
一切皆文件 ***********************************************LInux目录结构:***************************************** / (根): 所有目录都在 /boot : boot 配置文件、内核和其它启动时所需的文件(操作系统) /etc : 存放系统配置有关的文件 /home : 存放普通用户目录 /mnt : 硬盘上手动挂载的文件系统(插个U盘,把硬盘连接在系统上) /media : 自动挂载(加载)的硬盘分区以及类似CD、数码相机等可移动介质。 /cdrom : 挂载光盘? /opt : 存放一些可选程序,如某个程序测试版本,安装到该目录的程序的所有数据,库文件都存在同个目录下 /root : (根用户)系统管理员的目录,对于系统来说,系统管理员好比上帝,他可以对系统做任何操作,比如删除你的文件,一般情况下不要使用root用户。 /bin : 存放常用的程序文件(命令文件)。 /sbin : 系统管理命令,这里存放的是系统管理员使用的管理程序 /tmp : 临时目录,存放临时文件,系统会定期清理该目录下的文件。 /usr : 在这个目录下,你可以找到那些不适合放在/bin或/etc目录下的额外的工具。比如游戏、打印工具等。/usr目录包含了许多子目录: /usr/bin目录用于存放程序;

Why does sed add a new line in OSX?

为君一笑 提交于 2020-02-18 07:24:08
问题 echo -n 'I hate cats' > cats.txt sed -i '' 's/hate/love/' cats.txt This changes the word in the file correctly, but also adds a newline to the end of the file. Why? This only happens in OSX, not Ubuntu etc. How can I stop it? 回答1: echo -n 'I hate cats' > cats.txt This command will populate the contents of 'cats.txt' with the 11 characters between the single quotes. If you check the size of cats.txt at this stage it should be 11 bytes. sed -i '' 's/hate/love/' cats.txt This command will read

Linux下的sed命令使用详解

空扰寡人 提交于 2020-02-18 07:20:56
sed是stream editor的简称,也就是流编辑器。它一次处理一行内容,处理时,把当前处理的行存储在临时缓冲区中,称为“模式空间”pattern space,接着用sed命令处理缓冲区中的内容,处理完成后,把缓冲区的内容送往屏幕。接着处理下一行,这样不断重复,直到文件末尾。文件内容并没有 改变,除非你使用重定向存储输出。 使用语法 sed命令的使用规则是这样的: sed [option] 'command' input_file 其中option是可选的,常用的option有如下几种: -n 使用安静silent模式(想不通为什么不是-s)。在一般sed的用法中,所有来自stdin的内容一般都会被列出到屏幕上。但如果加上-n参数后,则只有经过sed特殊处理的那一行(或者动作)才会被列出来; -e 直接在指令列模式上进行 sed 的动作编辑; -f 直接将 sed 的动作写在一个文件内, -f filename 则可以执行filename内的sed命令; -r 让sed命令支持扩展的正则表达式(默认是基础正则表达式); -i 直接修改读取的文件内容,而不是由屏幕输出。 常用的命令有以下几种: a \:追加行append, a \的后面跟上字符串s(多行字符串可以用\n分隔),则会在当前选择的行的后面都加上字符串s; c \:取代/替换行change,c \后面跟上字符串s

mysql binlog日志解析

梦想的初衷 提交于 2020-02-18 06:47:57
-- 查看某个时间段的二进制日志,并且输出到指定的文件 mysqlbinlog --no-defaults --start-datetime="2018-12-12 13:00:00" --stop-datetime="2018-12-12 14:40:00" mysql-bin.000085 -vv --base64-output=decode-rows | more >> target.txt -- 将@1、@2等一系列看不懂的符号转换为SQL语句 cat target.txt | sed -n '/###/p' | sed 's/### //g;s/\/\*.*/,/g;s/DELETE FROM/INSERT INTO/g;' | sed -r 's/(@4.*),/\1;/g' | sed 's/@[0-9]*\=//g' > test.sql 来源: https://www.cnblogs.com/cjyboy/p/11134120.html