sed

Using sed to delete a string between parentheses

允我心安 提交于 2020-03-13 06:46:43
问题 I'm having trouble figuring how to delete a string in between parentheses only when it is in parentheses. For example, I want to delete the string "(Laughter)", but only when it's in parenthesis and not just make it a case sensitive deletion since a sentence within that string starts with Laughter. 回答1: I'm not sure I understand you correctly, but the following will remove text between parentheses: sed "s/[(][^)]*[)]/()/g" myfile (or as Llama pointed out in comments, just:) sed "s/([^)]*)/()

Using sed to delete a string between parentheses

我们两清 提交于 2020-03-13 06:45:10
问题 I'm having trouble figuring how to delete a string in between parentheses only when it is in parentheses. For example, I want to delete the string "(Laughter)", but only when it's in parenthesis and not just make it a case sensitive deletion since a sentence within that string starts with Laughter. 回答1: I'm not sure I understand you correctly, but the following will remove text between parentheses: sed "s/[(][^)]*[)]/()/g" myfile (or as Llama pointed out in comments, just:) sed "s/([^)]*)/()

I want to use “awk” or sed to print all the lines that start with “comm=” in a file

笑着哭i 提交于 2020-03-13 06:07:19
问题 I want to use "awk" or "sed" to print all the lines that start with comm= from the file filex , Note that each line contains "comm=somthing" for example : comm=rm , comm=ll, comm=ls .... How can i achieve that ? 回答1: For lines that start with comm= sed -n '/^comm=/p' filex awk '/^comm=/' filex If comm= is anywhere in the line then sed -n '/comm=/p' filex awk '/comm=/' filex 回答2: You could use grep also : grep comm= filex this will display all the lines containing comm= . 回答3: Here's an

I want to use “awk” or sed to print all the lines that start with “comm=” in a file

♀尐吖头ヾ 提交于 2020-03-13 06:06:30
问题 I want to use "awk" or "sed" to print all the lines that start with comm= from the file filex , Note that each line contains "comm=somthing" for example : comm=rm , comm=ll, comm=ls .... How can i achieve that ? 回答1: For lines that start with comm= sed -n '/^comm=/p' filex awk '/^comm=/' filex If comm= is anywhere in the line then sed -n '/comm=/p' filex awk '/comm=/' filex 回答2: You could use grep also : grep comm= filex this will display all the lines containing comm= . 回答3: Here's an

zabbix 自定义监控服务配置

倾然丶 夕夏残阳落幕 提交于 2020-03-12 13:12:27
注:本文基于 https://blog.51cto.com/14227204/2474670 一、监控主机内存使用情况 1、在服务器上部署agent客户端 [root@agent /]# mkdir /zabbix # 个人习惯,可忽略 [root@agent /]# cd /zabbix/ [root@agent /]# rz [root@agent zabbix]# tar zxf zabbix-3.2.1.tar.gz [root@agent zabbix]# cd zabbix-3.2.1/ [root@agent zabbix-3.2.1]# useradd -M -s /sbin/nologin zabbix [root@agent zabbix-3.2.1]# ./configure --prefix=/usr/local/zabbix --enable-agent && make && make install [root@agent zabbix-3.2.1]# cp misc/init.d/fedora/core/zabbix_agentd /etc/init.d/ [root@agent /]# sed -i 's/BASEDIR=\/usr\/local/BASEDIR=\/usr\/local\/zabbix/g' /etc/init.d/zabbix

sed delete lines between two patterns, without the second pattern, including the first pattern

只愿长相守 提交于 2020-03-11 14:56:33
问题 my input file looks like this: [1234] text text text [3456] text text text [7458] text text text I want to delete all lines between the patterns, including FROM_HERE and excluding TO_HERE. sed '/FROM_HERE/,/TO_HERE/{//p;d;}' Now i have: sed '/^\['"3456"'\]/,/^\[.*\]/{//p;d;}' but this command does not delete the line FROM_HERE too. for 3456 at the end the input file should look like: [1234] text text text [7458] text text text How can i achieve this? Thanks. 回答1: You could delete lines from

[转帖]SED 简明教程

我与影子孤独终老i 提交于 2020-03-09 07:38:45
SED 简明教程 https://coolshell.cn/articles/9104.html awk于1977年出生,今年36岁本命年,sed比awk大2-3岁,awk就像林妹妹,sed就是宝玉哥哥了。所以 林妹妹跳了个Topless ,他的哥哥sed坐不住了,也一定要出来抖一抖。 sed全名叫stream editor,流编辑器,用程序的方式来编辑文本,相当的hacker啊。sed基本上就是玩正则模式匹配,所以,玩sed的人,正则表达式一般都比较强。 同样,本篇文章不会说sed的全部东西,你可以参看 sed的手册 ,我这里主要还是想和大家竞争一下那些从手机指缝间或马桶里流走的时间,用这些时间来学习一些东西。当然,接下来的还是要靠大家自己双手。 用s命令替换 我使用下面的这段文本做演示: 1 2 3 4 5 6 7 8 9 $ cat pets.txt This is my cat my cat 's name is betty This is my dog my dog's name is frank This is my fish my fish's name is george This is my goat my goat's name is adam 把其中的my字符串替换成Hao Chen’s,下面的语句应该很好理解(s表示替换命令,/my/表示匹配my,/Hao

ubuntu apt命令行换源

孤人 提交于 2020-03-08 22:53:43
sed -i s@cn.archive.ubuntu.com@mirrors.ustc.edu.cn@g/etc/apt/sources.list && sed -i s@security.ubuntu.com@mirrors.ustc.edu.cn@g/etc/apt/sources.list && apt-get update 来源: CSDN 作者: nkenen 链接: https://blog.csdn.net/qq_26954059/article/details/104739427

linux运维、架构之路-正则表达式

南楼画角 提交于 2020-03-08 07:56:45
一、通配符的含义 符号 参数说明 其他说明 | 管道 把前一个命令结果通过管道传递给后面一个命令 ; 命令的分隔符 ll /oldboy/;cat oldboy.tx . 表示当前目录 * 匹配文本或字符串 ls *.txt,ls *.log / 根或路径的分隔符 && 命令分隔 表示并且,前一个执行成功才会执行后面的 $ 取变量的值 echo $PATH {} 配合echo 打印序列 echo {1..6} 通配符中以* 和{} 最为常用 1、举例说明 ①查找/oldboy下所有.txt文件 [root@oldboyedu37 oldboy]# find /oldboy -type f -name "*.txt" /oldboy/abc.txt /oldboy/oldboy.txt /oldboy/a.txt ②在/oldboy目录下批量创建10个以文件,例如:oldboy1-oldboy10.txt [root@oldboyedu37 oldboy]# touch oldboy{1..10}.txt [root@oldboyedu37 oldboy]# ls -lrt -rw-r--r-- 1 root root 0 Jun 5 17:58 oldboy9.txt -rw-r--r-- 1 root root 0 Jun 5 17:58 oldboy8.txt -rw-r--r

Delete a network profile from wpa_supplicant.conf in Linux (raspbian).

删除回忆录丶 提交于 2020-03-06 04:51:06
问题 I'm runnining Raspbian, but this is not a Pi specific question I need to delete from within my C program an unused network profile from etc/wpa_supplicant/wpa_supplicant.conf. My program runs as root. Is there a shell command for this ? I tried using combinations of grep, tr, and sed, but I'm not getting quite there. Also the white-spaces may vary. I need to remove this block for a given ssid, disregarding white-spaces. network={ ssid="MY_SSID_TO_DELETE" ......... } 回答1: SSID_TO_DELETE="Put