reg实践,题目答案构造

reg实践,题目答案构造

正则部分

匹配数字

[1-9].

匹配行首


 ^ matches at the start of the string

 $ matches at the end of the string
=======
 so you have 


 ^\s+

sed 部分

Linux sed 命令是利用脚本来处理文本文件。

sed 可依照脚本的指令来处理、编辑文本文件。

Sed 主要用来自动编辑一个或多个文件、简化对文件的反复操作、编写转换程序等。

ref

https://www.runoob.com/linux/linux-comm-sed.html

删除操作:d命令
删除空白行:

sed ‘/^$/d’ file
删除文件的第2行:

sed ‘2d’ file
删除文件的第2行到末尾所有行:

sed ‘2,$d’ file
删除文件最后一行:

sed ‘$d’ file
删除文件中所有开头是test的行:

sed '/^test/'d file

shell 部分

loop 流程

while 语句
while循环用于不断执行一系列命令,也用于从输入文件中读取数据;命令通常为测试条件。其格式为:

while condition
do
    command
done

以下是一个基本的while循环,测试条件是:如果int小于等于5,那么条件返回真。int从0开始,每次循环处理时,int加1。运行上述脚本,返回数字1到5,然后终止。

#!/bin/bash
int=1
while(( $int<=5 ))
do
    echo $int
    let "int++"
done

运行脚本,输出:

1
2
3
4
5

shell 变量

注意,变量名和等号之间不能有空格,这可能和你熟悉的所有编程语言都不一样

var=123

not:

var = 123

失败(败于号码错位)

eg:删除了第8行,尽管echo 可见是7

在这里插入图片描述

code:

#!/bin/bash

i=0
count=0

while (( $count<=223 ))
do
	((count=$i*6+1))
	sed -i "" "${count}d" ./meitimu.md
	echo $count
	((i=i+1))
done

最后还是使用了AS完成的

nice as

在这里插入图片描述

发布了216 篇原创文章 · 获赞 33 · 访问量 9万+

猜你喜欢

转载自blog.csdn.net/paulkg12/article/details/103735682