我有一个包含以下内容的文件:
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) 我有一个名为 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 中”进行比较,然后进行一些处理。
任何帮助将不胜感激。谢谢!