2016-04-28 76 views
-1

您好我有一个长的文件是这样的:如何使用命令行删除具有特殊字符的行?

information_1 this is my [email protected] 
information_2 this is my file....s...asdadada sdsfsd 
information_3 this is my [email protected] 
information_4 this is my filesasdadada 
information_5 this is my [email protected] 

而且我想这样的文件,whitout包含“@” charachter行:

information_2 this is my file....s...asdadada sdsfsd 
information_4 this is my filesasdadada 

我如何使用bash做像sed,awk等命令...?

回答

0

使用awk:

$ awk '!/@/' file 
information_2 this is my file....s...asdadada sdsfsd 
information_4 this is my filesasdadada 
3

随着SED:

sed '/@/d' file 

删除包含一个@所有行。

使用grep:

不包含一个 @
grep -v @ file 

输出线。

0

用Perl:

$ perl -ne 'print unless /@/' file 

要替换文件(也创建例如备份.BAK,文件更精确地重命名为file.BAK并使用相同的名称创建新文件)

$ perl -i.BAK -ne 'print unless /@/' file