Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

What regular expression should I use in order to remove exponential number terms and floating point numbers from a text file?

For example I have the following terms in my file:

-0.161678
relational
0.081827
5.936420e-01
-0.155506
Favori54
0.086938
1.187284e+00
-0.149283
0.091921
"External"
1.780926e+00
-0.143025

I would like my file only includes the following lines:

relational
Favori54
"External"
share|improve this question
    
How about this example? regexr.com?36grk It can probably refined/optimised, since this one might be slightly crude, but it does work for the example you provided. :) –  destiel starship Sep 27 '13 at 18:41

2 Answers 2

It looks to me like you want lines that begin with anything but a digit or the minus sign. This will get you that:

grep '^[^0-9,-]' file.txt
share|improve this answer
    
Did you test this? It won't work. The regular expression will only match any first non-digit or non-minus sign. Also even if you add the + symbol to the end of that, it would still not match for Favori54 –  destiel starship Sep 27 '13 at 19:20
    
I did test it, with the lines listed in the OP, and it worked for me. grep prints any lines containing the pattern -- in this case, any line that has any non-digit-or-minus character as its first character. Since the tags specify linux, grep will be available. –  evilsoup Sep 27 '13 at 19:28
    
Thanks for your solution but it's not as general as I need. The following one actually get all the things that I don't need. egrep -x '\-''\+''[[:digit:]]+''\.''[[:digit:]]+''\e''[[:punct:]]''[[:digit:]]+' How can I just reverse this?\ –  Umit Karabiyik Sep 27 '13 at 19:34
    
Found the solution! I just needed to ad -v parameter. Here is most general version: egrep -vx '\-''\+''[[:digit:]]+''\.''[[:digit:]]+''\e''[[:punct:]]''[[:digit:]]+' –  Umit Karabiyik Sep 27 '13 at 19:54
    
You should write that up as an answer (you can accept your own answer after two days IIRC). –  evilsoup Sep 27 '13 at 20:00

Try this:

awk '{if($1+0!=$1) print $0}' filename.txt

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.