IDEA2023.1.3破解,IDEA破解,IDEA 2023.1破解,最新IDEA激活码

一分钟sed入门(一分钟系列)

IDEA2023.1.3破解,IDEA破解,IDEA 2023.1破解,最新IDEA激活码

1、简介

sed是一种行编辑器,它一次处理一行内容。

2、sed调用方式

sed [options] ‘command’ file(s)

sed [options] -f scriptfile file(s)

第一种直接在命令行中执行,第二种把命令写到了脚本中,二者无本质区别。

示例(1):打印hello.txt的内容

sed -n p hello.txt

说明:

-n:sed会在处理一行文本前,将待处理的文本打印出来,-n参数关闭了这个功能

p:命令表示打印当前行

hello.txt:待处理的文件

这个指令相当于cat

3、定址

告诉sed你期望处理的行,由逗号分隔的两个数字表示,$符号表示最后一行;

当然也可以使用正则来定位期望处理的行。

示例(2):打印hello.txt的第二行到最后一行

sed -n ‘2,$’p hello.txt

示例(3):打印hello.txt中正则匹配”100″的行

sed -n ‘/100/’p hello.txt

4、基本命令

hello.txt的内容为

1 2 3
10 20 30
100 200 300

命令:a\

在匹配行的后面加入一行文本

示例(4)匹配100的行,后面加入一行”new line”

sed ‘/100/’a\ “new line” hello.txt

输出内容为:

1 2 3
10 20 30
100 200 300
new line

命令:i\

在匹配行的前面加入一行文本

示例(5)匹配100的行,前面加入一行”new line”

sed ‘/100/’i\ “new line” hello.txt

输出内容为:

1 2 3
10 20 30
new line
100 200 300

命令:c\

将匹配行替换为目的行

示例(5)匹配100的行,替换为”new line”

sed ‘/100/’c\ “new line” hello.txt

输出内容为:

1 2 3
10 20 30
new line

命令:d

将匹配行删除

示例(5)删除匹配100的行

sed ‘/100/’d hello.txt

输出内容为:

1 2 3
10 20 30

命令:s

将匹配行替换

详细命令为:s/pattern-to-find/replacement-pattern/g

pattern-to-find:被替换的串

replacement-pattern:替换成这个串

g:全部替换,默认只替换匹配到的第一个

示例(5)讲100替换为hello

sed ‘s/100/hello/g’ hello.txt

输出内容为:

1 2 3
10 20 30
hello 200 300

5、元字符集

^:匹配一行的开始

$:匹配一行的结束

.:匹配某个字符

[abc]:匹配指定范围字符

6、实用命令

匹配以10开头的行,并替换为yes,并输出

sed -n ‘s/^10/yes/p’ hello.txt

输出内容为:

yes 20 30
yes0 200 300

取出文件中行手的行号与冒号

设hello.txt的内容为

1:#!/bin/sh

2:cat hello.txt

3:exit

sed -n -e ‘s/^[0-9]\{1,\}://g’p hello.txt

输出结果为:

#!/bin/sh
cat hello.txt

exit

干货推荐

作者:58沈剑 | 来源公众号 | 架构师之路

文章永久链接:https://tech.souyunku.com/?p=10468


Warning: A non-numeric value encountered in /data/wangzhan/tech.souyunku.com.wp/wp-content/themes/dux/functions-theme.php on line 1154
赞(98) 打赏



未经允许不得转载:搜云库技术团队 » 一分钟sed入门(一分钟系列)

IDEA2023.1.3破解,IDEA破解,IDEA 2023.1破解,最新IDEA激活码
IDEA2023.1.3破解,IDEA破解,IDEA 2023.1破解,最新IDEA激活码

评论 抢沙发

大前端WP主题 更专业 更方便

联系我们联系我们

觉得文章有用就打赏一下文章作者

微信扫一扫打赏

微信扫一扫打赏


Fatal error: Uncaught Exception: Cache directory not writable. Comet Cache needs this directory please: `/data/wangzhan/tech.souyunku.com.wp/wp-content/cache/comet-cache/cache/https/tech-souyunku-com/index.q`. Set permissions to `755` or higher; `777` might be needed in some cases. in /data/wangzhan/tech.souyunku.com.wp/wp-content/plugins/comet-cache/src/includes/traits/Ac/ObUtils.php:367 Stack trace: #0 [internal function]: WebSharks\CometCache\Classes\AdvancedCache->outputBufferCallbackHandler() #1 /data/wangzhan/tech.souyunku.com.wp/wp-includes/functions.php(5109): ob_end_flush() #2 /data/wangzhan/tech.souyunku.com.wp/wp-includes/class-wp-hook.php(303): wp_ob_end_flush_all() #3 /data/wangzhan/tech.souyunku.com.wp/wp-includes/class-wp-hook.php(327): WP_Hook->apply_filters() #4 /data/wangzhan/tech.souyunku.com.wp/wp-includes/plugin.php(470): WP_Hook->do_action() #5 /data/wangzhan/tech.souyunku.com.wp/wp-includes/load.php(1097): do_action() #6 [internal function]: shutdown_action_hook() #7 {main} thrown in /data/wangzhan/tech.souyunku.com.wp/wp-content/plugins/comet-cache/src/includes/traits/Ac/ObUtils.php on line 367