LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-04-2010, 02:09 PM   #1
nasridine
Member
 
Registered: Jan 2010
Posts: 52

Rep: Reputation: 15
How to grep a negative number in a file


I wanted to grep the line in a file starts with -1.000000e+00.

Tried grep "-1.000000e+00" *, got error "grep: invalid option --".
Neither of the following works:
grep "\-1.000000e00" *
grep "1.000000e00" *

How do I grep a negative number with scientific notation?

Thanks
 
Old 03-04-2010, 02:13 PM   #2
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551
Try putting a double-dash directly after the `grep` command, to tell grep that there are no more options coming (thereby eliminating the trouble of a greppable item which begins with a dash):

Code:
sasha@reactor: echo "-1.000000e+00" | grep -- -1.000000e+00
-1.000000e+00
sasha@reactor:
Sasha
 
1 members found this post helpful.
Old 03-04-2010, 02:19 PM   #3
nasridine
Member
 
Registered: Jan 2010
Posts: 52

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by GrapefruiTgirl View Post
Try putting a double-dash directly after the `grep` command, to tell grep that there are no more options coming (thereby eliminating the trouble of a greppable item which begins with a dash):

Code:
sasha@reactor: echo "-1.000000e+00" | grep -- -1.000000e+00
-1.000000e+00
sasha@reactor:
Sasha
It works. Thanks
 
Old 03-04-2010, 09:28 PM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,260

Rep: Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328
Interesting, using the '\' works for me using grep (GNU grep) 2.5.1
eg
Code:
grep '\-1' t.t
-1.00+66e
grep "\-1" t.t
-1.00+66e
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Sed/awk/grep search for number string of variable length in text file Alexr Linux - Newbie 10 01-19-2010 02:34 PM
grep regex number decimal capital letter casperdaghost Linux - Newbie 4 08-22-2009 07:32 AM
HELP!!! how to use grep to extract a number khong1010 Programming 6 04-18-2008 01:01 AM
start grep at line number secretlydead Linux - General 2 09-20-2007 07:03 AM
Reading negative integers from a file? (C++, iostream library) -=zAe=- Programming 5 02-21-2005 01:59 PM


All times are GMT -5. The time now is 04:43 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration