Matching a decimal number?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Matching a decimal number?
# 1  
Old 07-19-2012
Matching a decimal number?

Hi everyone!

Easy question for everyone. I'm trying to run a command line to find an exact match of a decimal number within a file. The number can be a positive OR negative number. For instance, if I want to find only the number -1 in the file that has:

Code:
-17.6
-17
-16.3
-16.2
-15.7
-15.3
-15.2
-1
-14.7
-14.3
-11
-10.9
-10.1
-10
-9.1
-8.1

how can I do this?
I tried cat myfile.asc | sed -n '/-1/ p' but this doesn't seem to work :-(

Thanks!!

Last edited by joeyg; 07-19-2012 at 04:31 PM.. Reason: Please wrap data and sripts with CodeTags
# 2  
Old 07-19-2012
hi,

Code:
egrep '^-1$' myfile.asc

or

Code:
grep -w -- '-1' myfiles.asc

# 3  
Old 07-19-2012
Code:
grep '^-1$' filename

# 4  
Old 07-19-2012
that's great! However, is there any way to do this using awk/gawk instead?

Thanks
# 5  
Old 07-19-2012
Fixed string, whole line matching:
Code:
grep -Fxe -1

Regards,
Alister
# 6  
Old 07-19-2012
Hi
With awk

Code:
awk '/^-1$/ { print; }'

# 7  
Old 07-19-2012
this is perfect! Thanks guys!!
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Zero padding a Number before and after a decimal place

Hi I was hoping someone could help me with a sed script I am trying to write? I am on a Mac running ElCapitan I have some text that I have converted from a pdf that I want to format into an xml file. In the file I have managed to delete all the text I do not need. The text I have left is... (8 Replies)
Discussion started by: Paul Walker
8 Replies

2. Shell Programming and Scripting

awk decimal point numbers matching

Hi All, Can some one help me in identifying the significance of character "$" ,Which is playing critical role in matching decimal point numbers as below. $ echo "01#.01"|awk '{if ($0 ~ /^+(\.*)?$/) print}' $ echo "01#.01"|awk '{if ($0 ~ /^+(\.*)?/) print}' 01#.01 $ Regards, Rmkganesh. (3 Replies)
Discussion started by: rmkganesh
3 Replies

3. Shell Programming and Scripting

Sort Decimal number in UNIX

Hello Everyone, In one of my script, I would like to sort the decimal numbers. For e.g. If I have numbers like 1.0 1.1 1.2 2.0 2.1 3.0 4.0 5.0 6.0 7.0 7.1 7.10 7.2 7.3 7.4 7.5 7.6 7.7 7.8 7.9 I would like to sort them 1.0 1.1 1.2 2.0 2.1 3.0 4.0 5.0 6.0 7.0 7.1 7.2 7.3 7.4... (3 Replies)
Discussion started by: sachinrastogi
3 Replies

4. Shell Programming and Scripting

Decimal number calculation problem

I have a below snippet of code from my perl script and its causing a problem when the output of $lTAX is 0 (zero) its getting displayed as -0.00. I want output to be 0 not -0.00. Any help would be appreciated. #!/usr/bin/perl my $lTotA = 50.94; my $lVatA = 8.49; my $lAllocD; my $lAdjNr =... (4 Replies)
Discussion started by: Devesh5683
4 Replies

5. Shell Programming and Scripting

number of digits after decimal

Hi All, I have a file of decimal numbers, cat file1.txt 1.1382666907 1.2603107334 1.6118799297 24.4995857056 494.7632588468 560.7633734425 ..... I want to see the output as only 7 digits after decimal (5 Replies)
Discussion started by: senayasma
5 Replies

6. UNIX for Dummies Questions & Answers

check if a decimal number is greater than zero

Hello, In my code I am checking to see if a variable that contains a decimal number is greater than 0 in the following manner: if do something fi However I am getting the error message (if $i for the current iteration holds 9.6352) command 9.6352 is not found How can I rectify... (5 Replies)
Discussion started by: Gussifinknottle
5 Replies

7. Shell Programming and Scripting

Hex to decimal - Execute command for the matching part

Alo I have this input: 0x10=some text 0x20=some text 0x30=some text and want this output: 16=some text 32=some text 48=some text I want to use a command to convert from hex to decimal i.e.: $ echo $((0x15a)) or $ printf '%d\n' 0x15a I try to use something like this: sed... (5 Replies)
Discussion started by: chitech
5 Replies

8. Shell Programming and Scripting

Add zero in decimal number

echo "scale=2; 282.73/640" | bc This will print .44 How to make the variable as 0.44 (2 Replies)
Discussion started by: sandy1028
2 Replies

9. Shell Programming and Scripting

Test decimal number

Hi, I would like test if a number is a decimal number or not (9 Replies)
Discussion started by: francis_tom
9 Replies
Login or Register to Ask a Question