Linux运维-SHELL编程之正则表达式与流编辑处理器

Linux运维-SHELL编程之正则表达式与流编辑处理器

什么是正则表达式

正则表达式是一种用来描述字符序列的强大工具,通常用于字符串的匹配、搜索和替换操作。它由普通字符(例如字母、数字)和特殊字符(称为元字符)组成,通过这些元字符可以构建出具有特定模式的字符串。正则表达式在文本处理、数据提取、验证输入等方面都有广泛的应用。

我们可以理解为:正则表达式是一种字符串的抽象,代表符合某些要求的字符串的一个范式,在一般情况下只要满足了正则表达式的条件就会被认定为匹配成功

正则表达式基本内容

基本元字符

元字符描述
.匹配任意单个字符除了\n\r
^匹配字符串的开始
$匹配字符串的结束
*匹配前面的字符零次或多次
+匹配前面的字符至少一次或多次
?匹配前面的字符零次或一次
``
[]匹配括号内的所有字符,可在内部字符串首写^表示不匹配给定字符(例如[^ABC]
[-]匹配在连续范围内的字符
[^]匹配不在该组内的字符
()表示一个子表达式
{n}匹配时指定前面字符出现的重复次数必须为n
{n,}匹配时指定前面字符出现的重复次数至少为n,也可以指定至多出现次数{n,m}
\转义字符,用于匹配特殊字符
\<匹配一个词组开头的字串

正则表达式的贪婪(greedy)与非贪婪(non-greedy)指的是匹配模式下的不同行为。

  • 贪婪:正则表达式默认是贪婪的,即会尽可能匹配更多的字符。例如,对于正则表达式a.*b,如果用来匹配字符串aabb,它会匹配整个字符串,而不是只匹配到第一个b为止。
  • 非贪婪:通过在量词后面加上?可以实现非贪婪匹配,这样正则表达式会尽可能少的匹配字符。例如,对于正则表达式a.*?b,如果用来匹配字符串aabb,它会匹配到第一个ab为止,而不是匹配整个字符串。

在量词后面加上?可以使得量词变成非贪婪的,否则默认是贪婪的。

带反斜杠的元字符

元字符描述
\s用来匹配所有空白字符,包括换行符
\S用来匹配非空白符,不包括换行符
\w匹配字母,数字,下划线
\d用来匹配数字

分组与捕获元

在正则表达式中,分组和非捕获元是用来对子表达式进行分组或者控制匹配行为的元字符。

  • 分组:使用圆括号()来创建一个分组,可以对其中的子表达式进行分组,并对整个分组应用量词。例如,(?:...)是一个非捕获分组,不会捕获匹配的内容,而(abc)是一个捕获分组,会捕获匹配的内容以便后续使用。

  • 非捕获元:用于对子表达式进行分组但不捕获匹配的内容。它可以避免将匹配的内容存储在匹配结果中,仅用于分组或者应用量词。

非捕获元捕获元描述
(?:exp1)捕获 exp1,但不记住匹配项。这在需要分组,但不需要捕获匹配内容时很有用。
(?=exp1)匹配 exp1 前面的位置,但不消费任何字符。这称为正向先行断言。例如,(?=\d) 匹配一个数字前面的位置,但不匹配数字本身。
(?!exp1)匹配后面跟的不是 exp1 的位置。这称为负向先行断言。例如,(?!\d) 匹配后面不是数字的位置。
(?<=exp1)匹配 exp1 后面的位置,但不消费任何字符。这称为正向后行断言。例如,(?<=\d) 匹配一个数字后面的位置,但不匹配数字本身。
(?<!exp1)匹配前面不是 exp1 的位置。这称为负向后行断言。例如,(?<!\d) 匹配前面不是数字的位置。

可以通过索引来引用。在使用捕获元时,可以通过\1\2等来引用先前捕获的内容。

修饰符

修饰符描述
i执行对大小写不敏感的匹配。
m多行模式。改变 ^$ 的行为,使它们分别在行的起始和结束处匹配,而不是在整个输入字符串的起始和结束处匹配。
s单行模式。改变 . 的行为,使其匹配所有字符,包括换行符 \n
g全局模式。查找所有匹配项,而不是在找到第一个匹配项后停止。

正则表达式匹配实例

  • 匹配一个有效的IPv4地址,匹配形如192.168.1.1的IPv4地址:
^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$
  • 匹配一个日期(YYYY-MM-DD),匹配形如2024-04-01的日期:
^\d{4}-\d{2}-\d{2}$
  • 匹配一个有效的邮箱地址,匹配形如example@example.com的邮箱地址:
^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$
  • 匹配一个简单的HTML标签(不考虑属性),匹配形如<div>content</div>的简单HTML标签:
<[a-zA-Z][a-zA-Z0-9]*>(.*?)<\/[a-zA-Z][a-zA-Z0-9]*>
  • 匹配一个简单的URL(不考虑协议、端口和查询参数),匹配形如http://example.com的简单URL:
^(http|https):\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,}(\/\S*)?$

在之前的文章中我们介绍过[[...]]可以使用正则表达式:

if [[ "$string" =~ pattern ]]; thenecho "Matched"
fi

但是正则表达式使用更常见的地方并不在于此,而是流编辑处理器

文本查找工具grep

grep 是一个强大的文本搜索工具,常用于在文件中查找特定模式的文本行。以下是 grep 命令的一些常见用法:

  1. 基本用法:在文件中搜索指定模式的文本行。

    grep 'pattern' file.txt
    
  2. 递归搜索:在指定目录及其子目录中递归搜索匹配的文本行。

    grep -r 'pattern' directory/
    
  3. 忽略大小写:在搜索时忽略模式的大小写。

    grep -i 'pattern' file.txt
    
  4. 显示匹配行数:显示匹配到的文本行的行数。

    grep -c 'pattern' file.txt
    
  5. 显示不匹配行:显示不包含匹配模式的文本行。

    grep -v 'pattern' file.txt
    
  6. 显示匹配文本:仅显示匹配到的文本,而不显示整行。

    grep -o 'pattern' file.txt
    
  7. 显示匹配行及上下文:显示匹配到的文本行及其上下文行。

    grep -C 2 'pattern' file.txt  # 显示匹配行及其上下各两行
    
  8. 显示匹配行号:显示匹配到的文本行的行号。

    grep -n 'pattern' file.txt
    
  9. 限制搜索深度:在递归搜索时,限制搜索的深度。

    grep --max-depth=1 'pattern' directory/
    
  10. 扩展正则:当使用 -E 选项时,grep 将以扩展的正则表达式语法进行匹配

    grep -E 'pattern' file.txt
    

流编辑处理器sed

sed是一种在线的、非交互式的编辑器,它一次处理一行内容。处理时,把当前处理的行存储在临时缓冲区中,称为模式空间(patternspace)。接着用sed命令处理缓冲区中的内容,处理完成后,把缓冲区的内容送往屏幕。接着处理下一行,这样不断重复,直到文件末尾。文件内容并没有改变,除非使用重定向存储输出。Sed主要用来自动编辑一个或多个文件,简化了对文件的反复操作。

sed使用模式与常用选项

sed的使用模式一般是如下状态:

sed 选项 命令 文件
选项描述
-e <script>将指定的 script 用作 sed 命令。
-f <file>从指定文件中读取 sed 脚本。
-i <suffix>直接在文件中进行编辑,并可选地备份原始文件,备份文件的后缀名由 suffix 指定。
-n不输出模式空间的内容,只有通过命令显式指定打印内容时才会输出。
-r--regexp-extended使用扩展的正则表达式语法。
-s--separate将输入视为多个独立的文件。
-u--unbuffered使用无缓冲的输出。
-V--version显示 sed 的版本信息。

-e-f 是用于指定 sed 脚本的选项,但有一些区别:

  1. -e <script>: -e 选项允许在命令行上直接指定 sed 脚本可以多次使用 -e 选项,每次指定一个脚本,这些脚本将按照指定的顺序依次执行。例如:

    sed -e 's/abc/def/' -e 's/123/456/' input.txt
    

    这将依次执行两个替换操作,第一个将 abc 替换为 def,第二个将 123 替换为 456

  2. -f <file>: -f 选项允许从指定的文件中读取 sed 脚本。文件中的每一行都被视为一个 sed 命令。例如,如果有一个名为 script.sed 的文件包含以下内容:

    s/abc/def/
    s/123/456/
    

    可以像如下使用 -f 选项,这将会按照文件中的顺序依次执行两个替换操作:

    sed -f script.sed input.txt
    

我们接下来以如下文件来演示sed功能:

Hello, World!
This is a test file for sed.
It contains some sample text that can be used to test various sed commands.
Feel free to modify this file and experiment with different sed commands.
sed is a powerful stream editor.
It can perform a wide range of text processing functions.
Enjoy testing sed!

sed删除文件中指定行

  • 删除指令的基本格式如下,d表示执行删除操作
sed 选项 '/匹配条件/d' 文件名

注意,为了防止在shell中出现冲突,最好是使用强解析即'',避免造成命令歧义

  • 删除符合正则匹配条件的行
r123@localhost:~/shell_code$ sed -e '/commands/d' content.txt 
Hello, World!
This is a test file for sed.
sed is a powerful stream editor.
It can perform a wide range of text processing functions.
Enjoy testing sed!
  • 删除指定行号的内容
r123@localhost:~/shell_code$ sed -e '7d' content.txt 
Hello, World!
This is a test file for sed.
It contains some sample text that can be used to test various sed commands.
Feel free to modify this file and experiment with different sed commands.
sed is a powerful stream editor.
It can perform a wide range of text processing functions.
  • 删除指定行号范围内的行
r123@localhost:~/shell_code$ sed -e '3,4d' content.txt 
Hello, World!
This is a test file for sed.
sed is a powerful stream editor.
It can perform a wide range of text processing functions.
Enjoy testing sed!

注意,这里的行号还可以用$来指定最后一行

r123@localhost:~/shell_code$ sed -e '$d' content.txt 
Hello, World!
This is a test file for sed.
It contains some sample text that can be used to test various sed commands.
Feel free to modify this file and experiment with different sed commands.
sed is a powerful stream editor.
It can perform a wide range of text processing functions.
r123@localhost:~/shell_code$ sed -e '3, $d' content.txt 
Hello, World!
This is a test file for sed.

sed替换文件中的指定内容

  • 替换命令的格式如下,正则修饰符是可选的
sed 选项 's/匹配条件/用于替换的字符串/[正则修饰符]' 文件名

我们以将所有sed替换为SED:

r123@localhost:~/shell_code$ sed -e 's/sed/SED/g' content.txt 
Hello, World!
This is a test file for SED.
It contains some sample text that can be uSED to test various SED commands.
Feel free to modify this file and experiment with different SED commands.
SED is a powerful stream editor.
It can perform a wide range of text processing functions.
Enjoy testing SED!

/g表示全局匹配,如果不加的话,只会替换每行中的第一个sed

r123@localhost:~/shell_code$ sed -e 's/sed/SED/' content.txt 
...
It contains some sample text that can be uSED to test various sed commands.
...
  • 对匹配到的部分进行增加内容,即使用&表示匹配到的表达式
r123@localhost:~/shell_code$ sed -e 's/sed/&SED/g' content.txt 
Hello, World!
This is a test file for sedSED.
It contains some sample text that can be usedSED to test various sedSED commands.
Feel free to modify this file and experiment with different sedSED commands.
sedSED is a powerful stream editor.
It can perform a wide range of text processing functions.
Enjoy testing sedSED!

这种操作实质上是相当于使用了捕获元,只不过使用捕获元必须在扩展正则状态下:

r123@localhost:~/shell_code$ sed -r 's/(sed)/\1SED/g' content.txt 
Hello, World!
This is a test file for sedSED.
It contains some sample text that can be usedSED to test various sedSED commands.
Feel free to modify this file and experiment with different sedSED commands.
sedSED is a powerful stream editor.
It can perform a wide range of text processing functions.
Enjoy testing sedSED!
  • 特殊情况下的匹配替换:存在/在字符串中时,我们必须将/替换为#
r123@localhost:~$ echo '/abc/344555/abc' | sed -e 's#abc#&ABC#g'
/abcABC/344555/abcABC
r123@localhost:~$ echo '/abc/344555/abc' | sed -e 's#abc#&ABC/g'
sed: -e expression #1, char 12: unterminated `s' command
r123@localhost:~$ echo '/abc/344555/abc' | sed -e 's/abc/&ABC/g'
/abcABC/344555/abcABC

sed从其他文件中添加内容

  • 基本命令格式如下,不添加匹配条件时,默认添加到每一行后
sed -e '[/匹配条件/]r 其他文件名' 当前文件名
  • 在每一个符合匹配条件的行后增加文件内容
r123@localhost:~/shell_code$ echo 12345678 > 1.txt
r123@localhost:~/shell_code$ sed -e '/sed/r 1.txt' content.txt 
Hello, World!
This is a test file for sed.
12345678
It contains some sample text that can be used to test various sed commands.
12345678
Feel free to modify this file and experiment with different sed commands.
12345678
sed is a powerful stream editor.
12345678
It can perform a wide range of text processing functions.
Enjoy testing sed!
12345678
  • 在当前文件后追加新文件内容
r123@localhost:~/shell_code$ sed -r '$r 1.txt' content.txt 
Hello, World!
This is a test file for sed.
It contains some sample text that can be used to test various sed commands.
Feel free to modify this file and experiment with different sed commands.
sed is a powerful stream editor.
It can perform a wide range of text processing functions.
Enjoy testing sed!
12345678

sed文件内容另存为操作

  • 基本命令格式如下,不添加匹配条件时,默认另存整个文件
sed -e '[/匹配条件/]w 其他文件名' 当前文件名
r123@localhost:~/shell_code$ sed -e '/commands/w tmp.txt' content.txt 
Hello, World!
This is a test file for sed.
It contains some sample text that can be used to test various sed commands.
Feel free to modify this file and experiment with different sed commands.
sed is a powerful stream editor.
It can perform a wide range of text processing functions.
Enjoy testing sed!
r123@localhost:~/shell_code$ cat tmp.txt 
It contains some sample text that can be used to test various sed commands.
Feel free to modify this file and experiment with different sed commands.
  • 另存指定行的内容
r123@localhost:~/shell_code$ sed -e '1,3w tmp.txt' content.txt 
Hello, World!
This is a test file for sed.
It contains some sample text that can be used to test various sed commands.
Feel free to modify this file and experiment with different sed commands.
sed is a powerful stream editor.
It can perform a wide range of text processing functions.
Enjoy testing sed!
r123@localhost:~/shell_code$ cat tmp.txt 
Hello, World!
This is a test file for sed.
It contains some sample text that can be used to test various sed commands.

sed追加内容到指定位置

  • 基本命令格式如下,不添加匹配条件时,默认追加到每行之后
sed -e '[/匹配条件/]a追加内容' 文件名
r123@localhost:~/shell_code$ sed -e '/commands/a123456' content.txt 
Hello, World!
This is a test file for sed.
It contains some sample text that can be used to test various sed commands.
123456
Feel free to modify this file and experiment with different sed commands.
123456
sed is a powerful stream editor.
It can perform a wide range of text processing functions.
Enjoy testing sed!
  • 追加内容到指定范围的行后
r123@localhost:~/shell_code$ sed -e '3,5a123456' content.txt 
Hello, World!
This is a test file for sed.
It contains some sample text that can be used to test various sed commands.
123456
Feel free to modify this file and experiment with different sed commands.
123456
sed is a powerful stream editor.
123456
It can perform a wide range of text processing functions.
Enjoy testing sed!
  • 在一行后面追加多行内容
r123@localhost:~/shell_code$ sed -e '1a 233\23333\233333 ' content.txt 
Hello, World!
233
23333
233333 
This is a test file for sed.
...

命令ia的操作几乎是一致的,不过i的作用是在指定行的前面添加内容,这与a大同小异,故不多赘述:

r123@localhost:~/shell_code$ sed -e '3i123456' content.txt 
Hello, World!
This is a test file for sed.
123456
It contains some sample text that can be used to test various sed commands.
Feel free to modify this file and experiment with different sed commands.
sed is a powerful stream editor.
It can perform a wide range of text processing functions.
Enjoy testing sed!

sed进行整行替换操作

  • 基本命令格式如下,不添加匹配条件时,默认替换每一行
sed -e '[/匹配条件/]c追加内容' 文件名
  • 替换指定行号的内容
r123@localhost:~/shell_code$ sed -e '2c 233333333' content.txt 
Hello, World!
233333333
It contains some sample text that can be used to test various sed commands.
Feel free to modify this file and experiment with different sed commands.
sed is a powerful stream editor.
It can perform a wide range of text processing functions.
Enjoy testing sed!
  • 替换指定范围行号的内容为一行
r123@localhost:~/shell_code$ sed -e '1,2c233333333' content.txt 
233333333
It contains some sample text that can be used to test various sed commands.
Feel free to modify this file and experiment with different sed commands.
sed is a powerful stream editor.
It can perform a wide range of text processing functions.
Enjoy testing sed!

sed操作目标行的下一行

我们使用{}来包含多个命令来执行这一操作,n用于指定下一行:

sed 选项 '/匹配条件/{n;其他命令}' 文件名
r123@localhost:~/shell_code$ sed -r '/commands/{n; d}' content.txt
Hello, World!
This is a test file for sed.
It contains some sample text that can be used to test various sed commands.
sed is a powerful stream editor.
It can perform a wide range of text processing functions.
Enjoy testing sed!

sed命令反向操作文件

我们使用!来让命令作用范围反向操作:

r123@localhost:~/shell_code$ sed -e '/commands/!d' content.txt 
It contains some sample text that can be used to test various sed commands.
Feel free to modify this file and experiment with different sed commands.r123@localhost:~/shell_code$ sed -e '/commands/d' content.txt 
Hello, World!
This is a test file for sed.
sed is a powerful stream editor.
It can perform a wide range of text processing functions.
Enjoy testing sed!

sed执行多个操作的方式

  • 使用多个e选项执行
r123@localhost:~/shell_code$ sed -e '1d' -e '3d' content.txt 
This is a test file for sed.
Feel free to modify this file and experiment with different sed commands.
sed is a powerful stream editor.
It can perform a wide range of text processing functions.
Enjoy testing sed!
  • 使用分号分割命令
r123@localhost:~/shell_code$ sed -e '2d;3d' content.txt 
Hello, World!
Feel free to modify this file and experiment with different sed commands.
sed is a powerful stream editor.
It can perform a wide range of text processing functions.
Enjoy testing sed!
  • 使用{}执行多个命令
r123@localhost:~/shell_code$ sed -e '2,4{s/sed/&SED/g; s/commands/COMMANDS/g}' content.txt 
Hello, World!
This is a test file for sedSED.
It contains some sample text that can be usedSED to test various sedSED COMMANDS.
Feel free to modify this file and experiment with different sedSED COMMANDS.
sed is a powerful stream editor.
It can perform a wide range of text processing functions.
Enjoy testing sed!

流编辑处理器awk

awk是一种强大的文本处理工具,通常用于处理和分析文本文件中的数据。它以行为单位处理文本文件,可以根据指定的规则对文件进行处理和转换。awk的基本工作流程是读取文件的每一行,将每一行拆分成字段(默认以空格分隔),然后应用用户定义的操作对字段进行处理。

awk的基本结构如下:

awk 'pattern { action }' filename

其中,pattern是一个条件,用于指定何时执行actionaction是要执行的操作。如果没有提供filenameawk将从标准输入读取数据。

例如,要打印一个文件的第一列,可以使用以下命令:

awk '{ print $1 }' filename

这将打印文件中每一行的第一个字段(以空格分隔)。

注意:awk实质上是一种完整的编程语言,具有变量、数组、控制结构等基本编程元素。除了作为命令行工具使用外,awk也可以编写独立的awk脚本文件,其中包含更复杂的逻辑和功能。awk提供了丰富的内置函数和特殊变量,使其在文本处理和数据转换方面非常强大和灵活。

awk的工作流程

awk的工作流程通常如下:

  1. 读取文件awk从指定的文件或标准输入中逐行读取数据。
  2. 分割行:每行数据根据指定的分隔符(默认为空格)被拆分成多个字段。
  3. 匹配模式:对每一行数据,awk根据用户提供的模式进行匹配。模式可以是简单的条件,也可以是正则表达式。
  4. 执行动作:如果模式匹配成功,awk执行与模式关联的动作。动作可以是打印、计算、赋值等操作。
  5. 重复处理awk重复以上步骤,直到处理完所有输入数据。
  6. 输出结果:根据执行的动作,awk将生成的结果输出到标准输出或指定的文件中。

在分割行时,awk实质上是先将当前读取到的行的数据储存在$0,然后根据分割符将内容分组依次存储到$1$2,…

awk的命令结构

awk 选项 '命令' 文件名
选项功能
-F指定字段分隔符
-f指定awk脚本文件
-v定义awk变量
-i修改awk的工作模式
-W控制awk的警告消息
-o控制awk的输出格式
-O控制awk的输出字段
-F控制awk的输入字段

awk的特殊模式

awk中的BEGINEND是特殊模式,用于在处理输入之前和之后执行一次性操作。

  1. 使用BEGIN在处理之前打印标题:
awk 'BEGIN { print "Name\tAge\tGender" } { print $1 "\t" $2 "\t" $3 }' data.txt

这个命令在处理data.txt之前会打印一行标题,然后对每一行数据打印第一、第二、第三个字段。

  1. 使用END在处理之后打印汇总信息:
awk '{ total += $1 } END { print "Total: " total }' data.txt

注意:BEGINEND块中的代码只会执行一次,分别在处理开始和结束时执行。

awk简单使用案例

r123@localhost:~/shell_code$ sudo awk -F : 'BEGIN{ print "start"}{print $1" => "$2}END{print "end"}' /etc/passwdstart
root => x
daemon => x
bin => x
...
end

实质上使用的时候其他操作比较少见,sed就可以了,这里唯一需要注意的是,我们需要将其他的字符串以""包括

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/792546.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

精进TypeScript--优选接口的联合,而不是联合的接口

如果你创建的一个属性是联合类型的接口&#xff0c;你应该问一下这个类型作为更精确的接口的联合是否更有意义 要记住的事情&#xff1a; 具有多个属性对于联合类型的接口通常是一个错误的选择&#xff0c;因为它们掩盖了这些属性之间的关系接口的联合更精确&#xff0c;且可以…

Vben Admin实战-系统管理之用户管理-(第12节)

系列文章目录 第一节:Vben Admin介绍和初次运行 第二节:Vben Admin 登录逻辑梳理和对接后端准备 第三节:Vben Admin登录对接后端login接口 第四节:Vben Admin登录对接后端getUserInfo接口 第五节:Vben Admin权限-前端控制方式 第六节:Vben Admin权限-后端控制方式 第七节…

在 Jupyter Notebook 中切换环境

在 Jupyter Notebook 中切换环境&#xff0c;通常指的是在不同的 Python 环境&#xff08;如 conda 环境或 virtualenv 环境&#xff09;之间切换。以下是如何在 Jupyter Notebook 中切换环境的几种方法&#xff1a; 1. 使用 conda 如果你使用的是 conda 作为你的包和环境管理…

基于SSM实现的移动OA办公系统

系统介绍 基于SSM实现的移动OA办公系统设计了管理员、团队负责人、普通员工、部门负责人、人事部经理等几种用户角色 系统实现了如下功能&#xff1a; 管理员管理&#xff1a;用户管理、角色管理、权限管理、团队管理等功能 客户管理&#xff1a;客户管理、客户类型管理、状…

Uinx线程详解

目录 一.什么是线程&#xff1f; 并发&#xff08;Concurrency&#xff09; 并行&#xff08;Parallelism&#xff09; 1.1 线程的概念 1.2 线程的基本函数 1.3 线程的基本使用例子&#xff1a; 二.线程的属性 2.1线程属性使用例子 三.线程互斥 3.1互斥锁 3.2互斥锁常用函…

C语言笔试题之求解X的平方根

求解X的平方根 一、实例要求 1、给定一个非负整数 x &#xff0c;计算并返回 x 的算术平方根 &#xff1b;2、由于返回类型是整数&#xff0c;结果只保留整数部分 &#xff0c;小数部分将被舍去&#xff1b;3、不允许使用任何内置指数函数、运算符&#xff1b; 二、实例分析…

python作业

1.找出10000以内能被5或6整除&#xff0c;但不能被两者同时整除的数(函数) 2.写一个方法&#xff0c;计算列表所有偶数下标元素的和(注意返回值) 3.根据完整的路径从路径中分离文件路径、文件名及扩展名。 4.根据标点符号对字符串进行分行 5.去掉字符串数组中每个字符串的空格 …

江协STM32:定时器定时中断和定时器定时闹钟

定时器中断 新建文件 按这个图来编写程序 第一步&#xff1a;RCC开启时钟&#xff0c;定时器到基准时钟和整个外设到工作时钟就会同时打开 第二步&#xff1a;选择时基单元的时钟源&#xff0c;对于定时中断选择内部时钟源 第三步&#xff1a;配置时基单元&#xff0c;ARR,P…

Golang Channel底层实现原理

1、本文讨论Channel的底层实现原理 首先&#xff0c;我们看Channel的结构体 简要介绍管道结构体中&#xff0c;几个关键字段 在Golang中&#xff0c;管道是分为有缓冲区的管道和无缓冲区的管道。 这里简单提一下&#xff0c;缓冲区大小为1的管道和无缓冲区的管道的区别&…

维基百科推广方法及注意事项解析-华媒舍

1. 维基百科 维基百科是一个自由而开放的在线百科全书&#xff0c;由志愿者共同创建和编辑。它是全球最大的百科全书&#xff0c;包含了广泛的主题和知识。作为一个公共平台&#xff0c;维基百科是广告和宣传的禁区&#xff0c;但它可以是一个有效的推广工具&#xff0c;帮助您…

ENSP华为防火墙WEB登录操作指南

ENSP华为防火墙WEB登录操作指南 华为防火墙登录WEB 1、华为防火墙配置&#xff1a;&#xff08;需要在互联接口下放通https和ping&#xff09; int g0/0/0 service-manage https permit service-manage ping permit 2、电脑需要配置虚拟网卡 3、虚拟网卡与云和防火墙配置的IP地…

【学习心得】Numpy学习指南或复习手册

本文是自己在学习Numpy过后总是遗忘的很快&#xff0c;反思后发现主要是两个原因&#xff1a; numpy的知识点很多&#xff0c;很杂乱。练习不足&#xff0c;学习过后一段时间不敲代码就会忘记。 针对这两个问题&#xff0c;我写了这篇文章。希望将numpy的知识点织成一张网&…

【Vmware】 debian 12 安装教程

1.前提说明 VMware 17.5.1 (自行安装)&#xff0c;参考Debian 12maven 3.8.7git 2.39.2jdk 1.8 / 11 / 17 1.1.Debian 下载 访问(https://www.debian.org/download) 下载 Debian 这是 Debian 12&#xff0c;代号为 bookworm&#xff0c;网络安装&#xff0c;用于 64 位 PC&a…

机器学习算法与应用

机器学习是人工智能领域中的一个重要分支&#xff0c;它通过构建和训练模型来使计算机系统具备从数据中学习并做出预测或决策的能力。在这篇博客中&#xff0c;我们将深入探讨机器学习算法的基本原理、常见类型以及在实际应用中的案例。 机器学习算法概述 介绍机器学习的基本概…

PLC通过Modbus转Profine网关接温度传感器方案

Modbus转Profinet网关用于实现Modbus协议和Profinet协议之间的数据转换和传输。Modbus转Profinet网关接温度传感器的方案主要涉及将Modbus协议的温度传感器数据转换为Profinet协议&#xff0c;以便与工业自动化系统中的其他设备进行通信和数据交换。 以下是实现此方案的基本步骤…

[StartingPoint][Tier0]Mongod

Task 1 How many TCP ports are open on the machine? (机器上打开了多少个 TCP 端口&#xff1f;) Example: $ sudo nmap -sS -T4 10.129.222.112 -p 27017,22 2 Task 2 Which service is running on port 27017 of the remote host? (哪个服务正在远程主机的端口 270…

系统架构设计师-23年-论文题目

系统架构设计师-23年-论文题目 更多软考知识请访问 https://ruankao.blog.csdn.net/ 摘要字数在400字以内&#xff0c;可以分条叙述&#xff0c;但不允许有图、表、流程图。 正文字数为2000字至300字&#xff0c;文中可以分条叙述&#xff0c;但不要全部用分条叙述的方式。 …

设计模式总结-面向对象设计原则

面向对象设计原则 面向对象设计原则简介单一职责原则单一职责原则定义单一职责原则分析单一职责原则实例 开闭原则开闭原则定义开闭原则分析开闭原则实例 里氏代换原则里氏代换原则定义里氏代换原则分析 依赖倒转原则依赖倒转原则定义依赖倒转原则分析依赖倒转原则实例 接口隔离…

向量旋转操作之分段递归交换

开篇 这是对于之前一维向量左旋操作问题的最后一个解法&#xff0c;也是关于这个问题的最后一篇文章。在之前的文章中&#xff0c;我们分别用求逆法、取模置换法对该问题进行了解答&#xff0c;今天&#xff0c;使用的是分段递归的方式。 问题概要 将一个n元一维向量向左旋转i个…

深入了解JUnit 5:新一代Java单元测试框架

深入了解JUnit 5&#xff1a;新一代Java单元测试框架 近年来&#xff0c;Java领域的单元测试框架发展迅速&#xff0c;而JUnit 5作为JUnit系列的最新版本&#xff0c;为开发人员提供了更多的功能和灵活性。在本文中&#xff0c;我们将介绍JUnit 5&#xff0c;并探讨其与JUnit 4…