Bash 如何使用命令行删除具有某些特殊字符的行?
嗨,我有一个像这样的长文件:Bash 如何使用命令行删除具有某些特殊字符的行?,bash,shell,unix,command-line,command,Bash,Shell,Unix,Command Line,Command,嗨,我有一个像这样的长文件: information_1 this is my file....@s...asdadada information_2 this is my file....s...asdadada sdsfsd information_3 this is my file@sasdadada information_4 this is my filesasdadada information_5 this is my filesasdadada@ 我想要一个这样的文件,去
information_1 this is my file....@s...asdadada
information_2 this is my file....s...asdadada sdsfsd
information_3 this is my file@sasdadada
information_4 this is my filesasdadada
information_5 this is my filesasdadada@
我想要一个这样的文件,去掉包含“@”字符的行:
information_2 this is my file....s...asdadada sdsfsd
information_4 this is my filesasdadada
如何使用诸如sed、awk之类的bash命令?使用awk:
$ awk '!/@/' file
information_2 this is my file....s...asdadada sdsfsd
information_4 this is my filesasdadada
使用awk:
$ awk '!/@/' file
information_2 this is my file....s...asdadada sdsfsd
information_4 this is my filesasdadada
对于sed:
sed '/@/d' file
删除包含@
的所有行
对于grep:
grep -v @ file
不包含带sed的@
的输出行:
sed '/@/d' file
删除包含@
的所有行
对于grep:
grep -v @ file
使用perl时不包含@
的输出行:
$ perl -ne 'print unless /@/' file
要替换文件中的文件(也要创建备份.BAK,例如,更精确地将文件重命名为file.BAK并创建具有相同名称的新文件)
使用perl:
$ perl -ne 'print unless /@/' file
要替换文件中的文件(也要创建备份.BAK,例如,更精确地将文件重命名为file.BAK并创建具有相同名称的新文件)