当前位置: 首页 > wzjs >正文

合肥网站建设是什么意思wordpress 生成html

合肥网站建设是什么意思,wordpress 生成html,广告平台网,上海网站建设找站霸网络shell 编程之 sed sed 编辑器介绍 sed(流编辑器)是一种非交互式文本处理工具,基于预设规则逐行处理数据流(文件或管道输入)。它将当前行存入模式空间,按命令处理后输出到标准输出,不修改原始文…

shell 编程之 sed

sed 编辑器介绍

sed(流编辑器)是一种非交互式文本处理工具,基于预设规则逐行处理数据流(文件或管道输入)。它将当前行存入模式空间,按命令处理后输出到标准输出,不修改原始文件

工作流程
  1. 读取一行数据到模式空间;
  2. 按顺序执行编辑命令;
  3. 输出处理后的行;
  4. 重复直至所有行处理完毕。
命令格式
sed [options] 'script' [file1 file2...]  
  • 选项
  • 选项

    描述
    -e script显式指定编辑命令(可多条,用分号分隔)
    -f file从文件读取编辑命令
    -n禁止默认输出,需配合p等命令手动输出,默认就是改了也输出,不改原样输出
选项正则表达式类型支持的元字符示例
无 -r基本正则表达式^$.*[]\( \)|(需转义)sed 's/[0-9]*/num/'
-r扩展正则表达式所有基本元字符 + 、?()|{}(无需转义)sed -r 's/[0-9]+/num/'
命令执行方式
  1. 命令行直接定义单条命令
    echo "This is a test" | sed 's/test/big test/'  
    # 输出:This is a big test  
    
  2. 命令行定义多条命

1、无-e直接分号分隔

[root@free ~]# sed -e 's/brown/green/; s/dog/cat/' data1.txt
The quick green fox jumps over the lazy cat.
The quick green fox jumps over the lazy cat.
The quick green fox jumps over the lazy cat.
The quick green fox jumps over the lazy cat.
The quick green fox jumps over the lazy cat.
[root@free ~]# cat data1.txt 
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.

2、有-e直接空格分隔

[root@free ~]# sed -e 's/brown/green/' -e 's/dog/cat/'  data1.txt 
The quick green fox jumps over the lazy cat.
The quick green fox jumps over the lazy cat.
The quick green fox jumps over the lazy cat.
The quick green fox jumps over the lazy cat.
The quick green fox jumps over the lazy cat.

3、还可以换行输入

[root@free ~]# sed -e '                                           
s/brown/green/
s/dog/cat/
' data1.txt
The quick green fox jumps over the lazy cat.
The quick green fox jumps over the lazy cat.
The quick green fox jumps over the lazy cat.
The quick green fox jumps over the lazy cat.
The quick green fox jumps over the lazy cat.[root@free ~]# sed '{
> s/brown/green/
> s/dog/cat/
> }' data1.txt
The quick green fox jumps over the lazy cat.
The quick green fox jumps over the lazy cat.
The quick green fox jumps over the lazy cat.
The quick green fox jumps over the lazy cat.
The quick green fox jumps over the lazy cat

sed 编辑器基础

替换命令(s)与高级选项
  • 语法

  • 注意:不管后面有没有新加参数都一定要分隔符(一般为/,但是分隔符可以自己定义,改为其他的也行)结尾

    s/pattern/replace/[flags]  
    
     
    • flags替换标记
      标记描述示例
      数字替换第n处匹配s/test/trial/2:替换第 2 个test
      g全局替换所有匹配项s/test/trial/g:替换所有test
      p打印匹配行(需-nsed -n 's/test/trial/p' data.txt
      w file将结果写入文件sed 's/test/trial/w output.txt' data.txt
  • 替换分隔符
    当模式含/时,可用其他字符(如!)替代分隔符:

    sed -n 's!/bin/bash!/bin/csh!p' /etc/passwd  
    
使用地址(行寻址)
  • 数字寻址
    • 单一行号:2s/dog/cat/(修改第 2 行);
    • 行区间:2,3d(删除第 2-3 行);
    • 从某行到末尾:2,$s/old/new/$代表末行)。
  • 文本模式寻址
    sed -n '/redhat/s/bash/csh/p' /etc/passwd  # 仅处理含"redhat"的行  
    
  • 命令组合
    sed '2{  
    > s/fox/elephant/  
    > s/dog/cat/  
    > }' data1.txt  # 对第2行执行两条替换命令  
    
删除命令(d)
  • 按行号删除
    sed '3d' data4.txt  # 删除第3行  
    
  • 按模式删除
    sed '/number 1/d' data4.txt  # 删除含"number 1"的行  
    
  • 区间删除
    sed '/1/,/3/d' data4.txt  # 删除包含"1"和"3"的行区间  
    
 插入与附加命令(i/a)(\)
  • 插入命令(i):在指定行前添加新行(分隔符用\)
    [root@free ~]# sed '3i/hellow'  data1.txt 
    The quick brown fox jumps over the lazy dog.
    The quick brown fox jumps over the lazy dog.
    /hellow
    The quick brown fox jumps over the lazy dog.
    The quick brown fox jumps over the lazy dog.
    The quick brown fox jumps over the lazy dog.[root@free ~]# sed '3i\hellow'  data1.txt 
    The quick brown fox jumps over the lazy dog.
    The quick brown fox jumps over the lazy dog.
    hellow
    The quick brown fox jumps over the lazy dog.
    The quick brown fox jumps over the lazy dog.
    The quick brown fox jumps over the lazy dog.
    
  • 附加命令(a):在指定行后添加新行
    [root@free ~]# sed '3a\hellow'  data1.txt 
    The quick brown fox jumps over the lazy dog.
    The quick brown fox jumps over the lazy dog.
    The quick brown fox jumps over the lazy dog.
    hellow
    The quick brown fox jumps over the lazy dog.
    The quick brown fox jumps over the lazy dog.
    
  • 行末附加
    [root@free ~]# sed '$a\hellow'  data1.txt 
    The quick brown fox jumps over the lazy dog.
    The quick brown fox jumps over the lazy dog.
    The quick brown fox jumps over the lazy dog.
    The quick brown fox jumps over the lazy dog.
    The quick brown fox jumps over the lazy dog.
    hellow
    
 修改命令(c)(\)

data4.txt

This is line number 1.
This is line number 2.
This is line number 3.
This is line number 4.
  • 按行号修改
    sed '3c\This is a changed line.' data4.txt  # 修改第3行  
    
  • 按模式修改
    sed '/number 3/c\This is a changed line.' data4.txt  
    
转换命令(y)

data5.txt

This is line number 1.
This is line number 2.
This is line number 3.
This is line number 4.
This is line number 1 again.
This is text you want to keep.
This is the last line in the file.
  • 字符一对一转换
    sed 'y/123/789/' data5.txt  # 将"1"→"7","2"→"8","3"→"9"  
    
  • 全局转换:自动转换所有匹配字符,无需指定位置。
 打印命令(p、=、l)
  • p命令:打印匹配行(需-n
    sed -n '/number 3/p' data4.txt  
    
  • =命令:打印行号
    sed '=' data1.txt  # 输出行号与内容  [root@free ~]# sed '=' data1.txt 
    1
    The quick brown fox jumps over the lazy dog.
    2
    The quick brown fox jumps over the lazy dog.
    3
    The quick brown fox jumps over the lazy dog.
    4
    The quick brown fox jumps over the lazy dog.
    5
    The quick brown fox jumps over the lazy dog.
    
  • l命令:打印行及不可见字符(如制表符\t
[root@free ~]# cat data6.txt 
This line contains tabs.
  • sed -n 'l' data6.txt  [root@free ~]# sed -n 'l' data6.txt 
    This line contains tabs.$
    
文件操作命令(w/r)
  • 写入文件(w)
    sed '1,2w test.txt' data4.txt  # 将前两行写入test.txt  
    
  • 读取文件(r):在指定位置插入外部文件内容
    sed '3r data8.txt' data4.txt  # 在第3行后插入data8.txt内容  
    
 sed 案例

/etc/passwd 复制到/root/test.txt,用sed打印所有行;

  1. 打印文件所有行
    sed -n '1,$p' test.txt  
    
  2. 删除含特定字符的行
    sed '/bash/d' test.txt  
    
  3. 替换路径字符串(改变分隔符即可)
    sed 's#/sbin/nologin#/bin/login#' test.txt  
    
  4. 提取目录名与基名
    echo "/etc/sysconfig/network-scripts/" | sed -r 's#^/(.*)/(.*)/#\1#'  # 提取目录名 echo "/etc/sysconfig/network-scripts/" |sed -r 's#^/(.*)/(.*)/#\2#'  #提取基名
    .*是贪婪匹配,一直以匹配到最长,除非像以上后面还是字符限制如果只要取第一个目录名:
    [root@free ~]# echo "/etc/sysconfig/network-scripts/" | sed -r 's#^/([a-z]+)/(.*)/#\1#'
    etc()定义捕获组,\1是将匹配到的内容替换为第一个捕获组所匹配到的内容 提取目录名还能用dirname
    dirname /etc/httpd/conf.d/host.conf基名能用basename
    basename /etc/httpd/conf.d/host.conf
    
  5. 提取 IPv4 地址
    ifconfig | sed -n '2p' | sed -r "s/.*inet[[:space:]]*//; s/[[:space:]]*netmask.*//"  这是先取出第二行,然后将不需要的部分替换为空第二种方法
    [root@free ~]# ifconfig | sed -rn 's/.*inet ([0-9.]+).*/\1/p'
    192.168.153.135
    127.0.0.1定义捕获组为ipv4的格式,也可以使用更具体的匹配格式
    [root@free ~]# ifconfig | sed -rn 's/.*inet ([0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}).*/\1/p'
    192.168.153.135
    127.0.0.1如果想要去掉回环地址
    [root@free ~]# ifconfig | sed -rn 's/.*inet ([0-9.]+).*/\1/p' | grep -v '^127'
    192.168.153.135-v去掉满足要求的
  6. 在test.txt 20行到末行最前面加’aaa:’
sed '20,$s/^.*$/aaa:&/g' test.txt^.*$:正则表达式,匹配整行内容(^行首,.*任意字符,$行尾)。
aaa:&:替换文本,&是sed的特殊变量,表示匹配的内容(即整行)。

7.复制/etc/grub2.cfg/root/grub2.cfg,删除文件中所有以空白开头的行行首的空白字符;

sed 's/^\s*//' /etc/grub2.cfg
\s通常可以用来表示空白字符sed 's/^[[:space:]]//' grub2.cfg

8.关闭selinux功能

就是用-i将文件直接修改

将SELINUX=.*替换为SELINUX=disabled

它配置文件有将3种不同形式列出来

#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.

[root@free ~]# cat /etc/selinux/config ....
SELINUX=enforcing
....[root@free ~]# sed -i 's/SELINUX=.*/SELINUX=disabled/' /etc/selinux/config 
[root@free ~]# cat /etc/selinux/config # This file controls the state of SELinux on the system.
# SELINUX=disabled
# SELINUX=disabled
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
# See also:
# https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/9/html/using_selinux/changing-selinux-states-and-modes_using-selinux#changing-selinux-modes-at-boot-time_changing-selinux-states-and-modes
#
# NOTE: Up to RHEL 8 release included, SELINUX=disabled
# NOTE: Up to RHEL 8 release included, SELINUX=disabled
# fully disable SELinux during boot. If you need a system with SELinux
# fully disabled instead of SELinux running with no policy loaded, you
# need to pass selinux=0 to the kernel command line. You can use grubby
# to persistently set the bootloader to boot with selinux=0:
#
#    grubby --update-kernel ALL --args selinux=0
#
# To revert back to SELinux enabled:
#
#    grubby --update-kernel ALL --remove-args selinux
#
SELINUX=disabled
SELINUX=disabled
# SELINUXTYPE= can take one of these three values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected.
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted

修改完配置文件后要将虚拟机重启才能生效,reboot

getenforce可以查看selinux状态


文章转载自:

http://q1hkWKHa.qjtbt.cn
http://MYdtmLhD.qjtbt.cn
http://qJo7ERZP.qjtbt.cn
http://CbLJRzmf.qjtbt.cn
http://vWXfSG25.qjtbt.cn
http://8OCnx9M1.qjtbt.cn
http://AqQxpww5.qjtbt.cn
http://jAGkArXw.qjtbt.cn
http://yFQpOGFM.qjtbt.cn
http://9zBeNyxS.qjtbt.cn
http://0eOzFejc.qjtbt.cn
http://lyKmP4b9.qjtbt.cn
http://nvpU5FEe.qjtbt.cn
http://glh8c0C6.qjtbt.cn
http://eTP3KmGf.qjtbt.cn
http://T3O3ZaWx.qjtbt.cn
http://llzWovS3.qjtbt.cn
http://5JyPjEiD.qjtbt.cn
http://V3EtS6ti.qjtbt.cn
http://IVvYIF3g.qjtbt.cn
http://DdZkS2m8.qjtbt.cn
http://JzS9ojoQ.qjtbt.cn
http://wSUrLsDQ.qjtbt.cn
http://2EDujiad.qjtbt.cn
http://R5cXzLJa.qjtbt.cn
http://rwpcdNKO.qjtbt.cn
http://WEkeLcDr.qjtbt.cn
http://TOCZZ8ZE.qjtbt.cn
http://8mfiLWKO.qjtbt.cn
http://Azs4QoOX.qjtbt.cn
http://www.dtcms.com/wzjs/622053.html

相关文章:

  • 怎么看一个网站用什么系统做的wordpress 漫画站
  • 免费个人自助建站上海新政策
  • 音乐网站如何做网站建设文化公司
  • seo实训思考与总结南京seo网站优化
  • 数码产品网站模板Wordpress盗版主题
  • python 网站开发 用什么框架淄博 建设网站
  • 郑州餐饮网站建设公司排名php主做哪种类型网站
  • 网站建设平台报价北京手机网站搭建费用
  • 大型网站建设兴田德润实惠长沙房产网最新楼盘
  • 南通智能模板建站韩国最新新闻消息
  • 做保洁网站找谁做百度下载安装官方下载
  • 网站建设业务怎么做网站开发的甘特图
  • 微网站开发的比较总结仙居建设局网站
  • 公司网站昆明市网站推广
  • 手机网站下拉列表seo网站导航建设技巧
  • 徐州建设网站价格手机版html编辑软件
  • 网站的源码佛山专业外贸网站建设
  • 和幼儿做网站爱哔哩哔哩网页版在线观看
  • 做图书馆网站简单电商平台开发设计
  • 做网站从什么做起广西壮族自治区行政执法人员网络培训系统
  • 建设银行网站如何修改账单地址网络文化经营许可证价格
  • 网站建设服务器网站建设方案如何写
  • 北京营销型网站建设培训班国内国际时事写实记录50字配图片
  • 在线crm在线oa免费观看郑州百度搜索优化
  • 制作彩票网站需要多少钱北京律师24小时电话
  • 厦门seo网站关键词优推广wordpress安装出问题
  • 外贸网站开发推荐网络管理专业
  • 淘宝建设网站的目的是什么wordpress 图床 转移
  • 东莞如何建设网站制作平台网页美工设计photoshop 规划教材
  • 网站维护一般都是维护什么网页什么设计