小编age*_*on7的帖子

删除行范围,但跳过行之间的注释

我有一个包含以下内容的文件:

Windows user
I love windows
Windows 10
# I like it
# I want to keep these two lines
Just started with my job
New to shell scripting as well
New to Mac
Please help!

#EOF
Run Code Online (Sandbox Code Playgroud)

我想删除所有行:

从 " I love windows" 到 " New to shell scripting as well",但保留这些行之间的注释。

因此,所需的输出应如下所示:

Windows user
# I like it
# I want to keep these two lines
New to Mac
Please help!

#EOF
Run Code Online (Sandbox Code Playgroud)

我使用sed命令使用行号删除行范围

sed '2,7d' file …
Run Code Online (Sandbox Code Playgroud)

sed text-processing

3
推荐指数
1
解决办法
181
查看次数

如何使用 while 循环逐行读取文件中的行,并在每次迭代中,grep 每一行以与字符串进行比较?

我有一个名为 abc.txt 的文件,其内容如下:

1: It is a shell script
2: There are few lines in this file
3: I am good with programming in C, but beginner in shell
4: We are going towards end of file
5: END OF FILE
Run Code Online (Sandbox Code Playgroud)

我想迭代地读取每个文件,并且在每次迭代中,我想将这行与“我擅长 C 编程,但初学者在 shell 中”进行比较,然后进行一些处理。

任何帮助将不胜感激。谢谢!

command-line grep

2
推荐指数
2
解决办法
4332
查看次数

标签 统计

command-line ×1

grep ×1

sed ×1

text-processing ×1