首页 > 其他分享 >[Bash] sed command

[Bash] sed command

时间:2024-05-17 14:10:54浏览次数:17  
标签:sample sed command file World txt Bash

The sed command is a stream editor used for filtering and transforming text.

sed 'command' file

Create and view the initial content of sample.txt:

echo -e "Hello World\nThis is a sample file\nBash scripting is powerful\nLearning grep, awk, and sed\nAnother line with the word World" > sample.txt
cat sample.txt

Output:

Hello World
This is a sample file
Bash scripting is powerful
Learning grep, awk, and sed
Another line with the word World

Substitute a string in the file:

sed 's/World/Universe/g' sample.txt

Hello Universe
This is a sample file
Bash scripting is powerful
Learning grep, awk, and sed
Another line with the word Universe

Edit files in place:

sed -i '' 's/sample/example/g' sample.txt

Delete lines containing the word "Bash":

sed '/Bash/d' sample.txt

Hello World
This is a example file
Learning grep, awk, and sed
Another line with the word World

标签:sample,sed,command,file,World,txt,Bash
From: https://www.cnblogs.com/Answer1215/p/18197684

相关文章

  • flutter 运行ios真机测试 提示 Command PhaseScriptExecution failed with a nonzero
    我这边引起CommandPhaseScriptExecutionfailedwithanonzeroexitcode的原因是我刚更换了推送证书,于是我打开钥匙串访问发现推送证书处于不受信任状态,于是把证书状态设置为信任状态并删除了旧的推送证书,设置完成后再去运行,就可以成功运行了。这是我这边的单一情况,......
  • 解决jenkins构建时docker.command.not.found
    前提查看查看下面两个文件,如果宿主机没有,就不用跟着文档做了[root@localhost~]#ll/var/run/docker.socksrw-rw----.1rootdocker05月1613:37/var/run/docker.sock[root@localhost~]#[root@localhost~]#ll/usr/bin/docker-rwxr-xr-x.1rootroot39708368......
  • 通过BASH脚本实现DNS优选
    02***/root/mysqlbeifen.sh*/10****/root/dns_update.sh#!/bin/bashLOG_DIR="/var/log/dns_script"HOST_FILE="/etc/hosts_NC"DOMAIN="sso.ccnhub.com"DNS_SERVER="114.114.114.114"#ReplacewithyourDN......
  • bash脚本监控服务器SSH登录,每30分钟运行一次,发现登录发送到企业微信群
    //开始循环检测//loopCheck();//在每分钟的第30秒执行目标函数cron.schedule('358***',()=>{console.log('目标函数在8:35执行!');loopCheck_info();//在这里调用你想要定时执行的函数});cron.schedule('*/309-20***',()=>{con......
  • 部署freeipa中报错:Command '/bin/systemctl start certmonger.service' returned non-
    cat/etc/dbus-1/system.d/certmonger.conf<allowsend_destination="org.fedorahosted.certmonger"send_interface="org.fedorahosted.certmonger"/><allowsend_destination="org.fedorahosted.certmonger"......
  • Linux系统 输入vim 提示command not found
    让我想起了我面试的时候,面试官说你了解Linux系统吗?我说我不......他说好的,请问你平时怎么编辑文件呢。我说vim,进入编辑模式之后按照文档里面......他说如果没有vim呢?我说那就用自带的吧?他说自带的叫什么呢?我:......他:......他突然说:你平时抽烟吗?我:......whatcanisay......
  • sed 语法
    删除一行sed-i'/CONFIG_SERIAL_MSM=y/d'  ../src/kernel/msm-5.4/arch/arm/configs/vendor/test.config增加一行sed-i'$aCONFIG_SERIAL_MSM=y'  ../src/kernel/msm-5.4/arch/arm/configs/vendor/test.config   ......
  • 正则表达式 grep sed awk
    正则表达式表示字符匹配. 匹配任意单个字符,可以是一个汉字[] 匹配指定范围内的任意单个字符,示例:[zhou] [0-9] [] [a-zA-Z][[:alpha:]][0-9a-zA-Z]=[:alnum:][^]匹配指定范围外的任意单个字符,示例:[^zhou][^a.z][a.z][:alnum:]字母和数字[:alp......
  • [shell:bash] ubuntu_remove_old_kernel_test
    [shell:bash]  ubuntu_remove_old_kernel_test    一、基本信息 1、os:Linuxubuntu6.5.0-35-generic#35-UbuntuSMPPREEMPT_DYNAMICFriApr2611:23:57UTC2024x86_64x86_64x86_64GNU/Linux 2、bash:GNUbash,version5.2.......
  • Linux错误:-bash: Su: command not found
     问题:使用su命令出错:-bash:Su:commandnotfound 解决:先查看/etc/sudoers.d文件是否存在find/etc/sudoers.d说明系统已经安装了sudo,只不过没有配置环境。解决一:使用vi或vim以下命令打开/etc/sudoers文件。vim/etc/sudoers esc-->:......