删除外壳中以字符开头的行 [英] Remove the lines starting with a character in shell
本文介绍了删除外壳中以字符开头的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的数据集为:
file.txt
de
fds
fds
a
sa
1
2
3
1
}
我想删除所有以字符或特殊字符开头的行.所以我的档案是:
I would like to delete all the lines starting with characters or special characters. So my outfile is:
out.txt
1
2
3
1
我可以使用'sed'手动完成此操作,但是我正在为此寻找合适的命令.
I could do it manually with 'sed', but I am looking for a suitable command for this.
我的代码:
sed -i '/d//g' file.txt
sed -i '/f//g' file.txt
sed -i '/a//g' file.txt
sed -i '/s//g' file.txt
sed -i '/}//g' file.txt
推荐答案
使用 grep
和 -E
选项进行正则表达式(或简称egrep):
Use grep
with -E
option for regex (or egrep in short):
grep -E "^[0-9].*" file.txt
这篇关于删除外壳中以字符开头的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文