sed

sed命令简介

一个人想着一个人 提交于 2020-02-17 21:52:59
sed处理时,有2个缓冲区:【pattern space】和【hold space】 sed执行过程: 先读入一行,去掉尾部换行符,存入【pattern space】,执行编辑命令。 处理完毕,除非加了-n参数,把现在的【pattern space】打印出来,在后边打印曾去掉的换行符。 把【pattern space】置空。 接着读下一行,处理下一行。 sed的默认输出:【pattern space】里的内容输出到标准输出。 常用选项: 【pattern space】里的内容不输出到标准输出:-n 默认只能执行一个脚本,执行多个脚本:-e script, --expression=script 可以有多个-e script 如果要执行的脚本特别多,可以指定一个脚本文件:-f /path/to/sed_scirpt 脚本文件里,每行一个编辑命令。 支持使用扩展的正则表达式,默认是基本正则表达式:-r 直接编辑原文件:-i 地址定界: 1,不给地址:对全文进行处理 2,单地址 #:指定行 /pattern/:被此模式所匹配到的每一行 3,地址范围 $:最后一行 #,#:起始和结束 #,+#:起始,和从起始加多少行 #,/pat1/:起始到,pat1匹配到的行 /pat1/,/pat2/:pat1匹配到的行,到pat2匹配到的行 4,步进:~ 1~2:1,3,5,7,9.。。行

sed awk

不问归期 提交于 2020-02-17 09:56:55
1 替换文件某一行 将文件./config/patchconfig/patch_config.json 的第二行替换为 "path": "../patchfiles", 将文件aaa.txt中的第三行替换为888 content='"path": "../patchfiles", ' sed -i "2c${content}" ./config/patchconfig/patch_config.jsonsed -i '3c888' ./aaa.txt 参考: https://blog.csdn.net/nanaranran/article/details/81203905 https://www.cnblogs.com/seasonzone/p/11274788.html https://zhidao.baidu.com/question/878349927740895212.html 来源: https://www.cnblogs.com/wolbo/p/12320327.html

sed: -e expression #1, char 7: unterminated `s' command 错误解决

北慕城南 提交于 2020-02-17 09:14:36
学习sed,,跟着教程 pang@cdd : ~ / shelltest$ sed `s / 192.168 / hello / g` sed . txt - bash : s / 192.168 / hello / g : No such file or directory sed : - e expression # 1 , char 7 : unterminated `s' command 出现这种错误, 后来发现是 s/192.168/hello/g 这里出现了问题,这里是单引号不是·(和~在一起的那个符号) 来源: CSDN 作者: 泰勒朗斯 链接: https://blog.csdn.net/weixin_43360707/article/details/104333503

linux shell学习之 sed(基本用法)

孤者浪人 提交于 2020-02-17 02:37:08
一、概述 sed是一种流编辑器,与交互式编辑器不同,流式编辑器会在处理数据之前基于预先提供的一组规则来编辑数据流。 sed可以从标准输入(stdin)获取输入,处理结果从标准输出(stdout)输出。sed会一行一行地读入输入,然后按照预设命令对每行数据进行操作,若输入的是一个文件的内容,sed不会在源文件上修改,而只是在标准输出打印结果。 二、用法初涉 1、替换操作 echo "hello world" | sed 's/hello/HELLO/' 结果:hello world会被替换为HELLO world并从标准输出输出,命令‘s’是替换的意思。 2、多命令操作 使用分号隔开多命令 echo "hello world" | sed 's/hello/HELLO/;s/world/WORLD/' 或者直接换行,每行一个命令 echo "hello world" | sed ' >s/hello/HELLO/ >s/world/WORLD/' 两种操作的结果都是把hello world替换为HELLO WORLD。(我看的参考书里面说多命令要加上-e选项,但我没有加也可以完成操作。) 3、将命令存储在文件中 若有很多的命令,可以预先将命令存放在文件中,每行一个操作命令,在sed中使用-f选项指定从该文件中读取命令即可。 比如cmd.sed文件中存放以下命令 s/hello

Linux常用命令

限于喜欢 提交于 2020-02-16 22:13:36
系统信息 yum remove package_name 删除一个rpm包 yum list 列出当前系统中安装的所有包 yum search package_name 在rpm仓库中搜寻软件包 yum clean packages 清理rpm缓存删除下载的包 yum clean headers 删除所有头文件 yum clean all 删除所有缓存的包和头文件 YUM 软件包升级器 - (Fedora, RedHat及类似系统) yum install package_name 下载并安装一个rpm包 yum localinstall package_name.rpm 将安装一个rpm包,使用你自己的软件仓库为你解决所有依赖关系 yum update package_name.rpm 更新当前系统中所有安装的rpm包 yum update package_name 更新一个rpm包 DEB 包 (Debian, Ubuntu 以及类似系统) dpkg -i package.deb 安装/更新一个 deb 包 dpkg -r package_name 从系统删除一个 deb 包 dpkg -l 显示系统中所有已经安装的 deb 包 dpkg -l | grep httpd 显示所有名称中包含 "httpd" 字样的deb包 dpkg -s package_name

16、TextDisplay

好久不见. 提交于 2020-02-16 18:03:10
1、Tracking : TextBlock 和 RichTextBlock 中字符的间距可以通过 CharacterSpacing 属性进行设置。 CharacterSpacing 是 'em' 的 1/1000, 1 em 代表控件中 1 个字符的高度。例如,如果 TextBook 控件设置为 FontSize='14', 把 CharacterSpacing 设置为 CharacterSpacing='1000' , 则本 TextBlock 中文本之间的间隔为 14 px。 例如,下面的 xaml : <Slider x:Name="characterSpacingSlider" Width="200" Value="1" Maximum="500" Minimum="-100" TickFrequency="100"/> <TextBlock Style="{StaticResource BasicTextStyle}" //把 CharacterSpacing 属性绑定到 slider 的 value 上 CharacterSpacing="{Binding Value, ElementName=characterSpacingSlider}" Text="TextBlock with tracking applied via the CharaterSpacing

shell文本处理 sed命令

江枫思渺然 提交于 2020-02-16 13:10:05
1.定义 2.表示方法 1.2s表示只替换第二行 2. 3.可以将想要的操作写进文件里,然后调用文件 3.对字符的处理方式 p 显示 d 删除 a 添加 c 替换 w 写入 i 插入 4.参数 -e<script>或--expression=<script> 以选项中指定的script来处理输入的文本文件。 -f<script文件>或--file=<script文件> 以选项中指定的script文件来处理输入的文本文件。 -h或--help 显示帮助。 -n或--quiet或--silent 仅显示script处理后的结果。 -V或--version 显示版本信息。 5.示例 1.默认只替换每行第一个匹配的,加g表示全局替换: 数字表示第几次匹配到的: 2. -n 加 p 表示只输出经过修改的: 3.w表示将修改的结果写进文件中 4.替换字符: 有三种方式: sed 's/\/aaa\/bbb/\/ccc\/ddd/' data 将 /aaa/bbb 替换为 /ccc/ddd ,转义 / sed 's!/aaa/bbb!/ccc/ddd!' data 后两种方法更常用 sed 's#/aaa/bbb#/ccc/ddd#' data 5.结合正则表达式使用 6.删除 7.插入 8.追加 添加到数据流末尾: 9.修改 10.y 替换命令(处理单个字符) 来源: CSDN 作者:

pattern space and hold space of sed

半世苍凉 提交于 2020-02-13 09:50:16
Copied from: stackoverflow When sed reads a file line by line, the line that has been currently read is inserted into the pattern buffer (pattern space). Pattern buffer is like the temporary buffer, the scratchpad where the current information is stored. When you tell sed to print, it prints the pattern buffer. Hold buffer / hold space is like a long-term storage, such that you can catch something, store it and reuse it later when sed is processing another line. You do not directly process the hold space, instead, you need to copy it or append to the pattern space if you want to do something

sed and Mac OS X differences with to upper, to lower and whole capture control sequences

旧街凉风 提交于 2020-02-13 04:51:08
问题 I am trying to take the last two letters out of a filename which are uppercase and append them to the filename in lowercase. I expeceted the command: ls | sed -e "s/.*\([A-Z][A-Z]\)$/\0\/\L\1\E/" to achieve this and on my Ubuntu box it worked fine but on my Mac it simply prints out a 0/LXXE/ where XX are the correct letters from the capture. What are the Mac sed equivalents of \0 , \L and \E ? I've had a look around the web and several people have noticed that Mac OS X sed is different from

bash, extract string before a colon

*爱你&永不变心* 提交于 2020-02-12 06:50:47
问题 If I have a file with rows like this /some/random/file.csv:some string /some/random/file2.csv:some string2 Is there some way to get a file that only has the first part before the colon, e.g. /some/random/file.csv /some/random/file2.csv I would prefer to just use a bash one liner, but perl or python is also ok. 回答1: cut -d: -f1 or awk -F: '{print $1}' or sed 's/:.*//' 回答2: Another pure BASH way: > s='/some/random/file.csv:some string' > echo "${s%%:*}" /some/random/file.csv 回答3: Try this in