删除以shell中的字符开头的行,但保留负值 [英] Remove the lines starting with a character in shell, but preserve the negative values
本文介绍了删除以shell中的字符开头的行,但保留负值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有数据集:
file.txt
de
fds
fds
a
sa
-1
2
-3
1
}
我想删除所有以字符或特殊字符开头的行,但保留负值。所以我的outfile是:
out.txt
-1
2
-3
1
这个问题与我之前的一个问题有关删除在shell中的一个字符开始的行,我可以删除所有行包括负号。
我需要修改我的代码。
我的代码:
grep -E^ [0-9]。*file.txt
$ div class =h2_lin>解决方案
您可以尝试这样:
grep'^ * [ - +] \?[0-9] \ +'file.txt> out.txt
(或)
grep -E'^ * [ - +]?[0-9] +'file.txt> out.txt
I have dataset as:
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, but preserve the negative values. So my outfile is:
out.txt
-1
2
-3
1
This question is related to one of my earlier questions Remove the lines starting with a character in shell with which I can remove all lines starting with a character including negative sign.
I need to modify my code.
my code:
grep -E "^[0-9].*" file.txt
解决方案
You can try like this:
grep '^ *[-+]\?[0-9]\+' file.txt > out.txt
(Or)
grep -E '^ *[-+]?[0-9]+' file.txt > out.txt
这篇关于删除以shell中的字符开头的行,但保留负值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文