Grep float/integers but skip some integers


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Grep float/integers but skip some integers
# 8  
Old 04-09-2013
Many thanks hanson!
# 9  
Old 04-09-2013
Try this simple sed regex:
Code:
$ sed 's:^\([^-+0-9]*\|.*)\)::g' file

11 +/- 1.02651
11
 -9.84211
 11
 0.202636
 +11

# 10  
Old 04-09-2013
Sorry but this command doesn't do anything for me.
Quote:
Originally Posted by RudiC
Try this simple sed regex:
Code:
$ sed 's:^\([^-+0-9]*\|.*)\)::g' file

# 11  
Old 04-10-2013
With your file from post#1:
Code:
$ sed 's:^\([^-+0-9]*\|.*)\)::g' file


11 +/- 1.02651
11
 9.84211
 11
 0.202636
 11

# 12  
Old 04-10-2013
Yes, still i am using the same input file but i don't see any effect of this sed command. I don't know why we see different results.
# 13  
Old 04-11-2013
OK, mayhap your sed doesn't like the ORed regex. Try:
Code:
sed 's:^[^-+0-9]*::g; s:^.*)::' file
11 +/- 1.02651
11
 9.84211
 11
 0.202636
 11

This User Gave Thanks to RudiC For This Post:
# 14  
Old 04-11-2013
Quote:
Originally Posted by RudiC
OK, mayhap your sed doesn't like the ORed regex. Try:
Code:
sed 's:^[^-+0-9]*::g; s:^.*)::' file
11 +/- 1.02651
11
 9.84211
 11
 0.202636
 11

Yes, you are right. It works fine. Thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Comparing Integers (I think)

Hi, I can't figure out what I'm missing. I'm running a query to see if there are any streams recording on my DVR before starting a scripted update. I'm guessing that it is viewing $VIDEO as a string instead of an int. I've tried everything I saw on google but it still comes back as $VIDEO is... (8 Replies)
Discussion started by: Rhysers
8 Replies

2. UNIX for Dummies Questions & Answers

Strings to integers?

Hi, I'm totally new at this, so help will be appreciated. I have a directory with a bunch of files in it. The files are named xinteger_yinteger_zinteger.vtk (eg, x3_y0_z-1.vtk). I want to read the filenames and then assign the integers to variables that I then can use in expressions. So, for... (6 Replies)
Discussion started by: jhsinger
6 Replies

3. Shell Programming and Scripting

Bash Integers/String

Hy friends, I am newbie to bash scripting, can anyone explain how b=${a/23/BB} # Substitute "BB" for "23". this line converts "b" into string and and "d" into Integer. Thanks in advance (4 Replies)
Discussion started by: Qazi
4 Replies

4. Shell Programming and Scripting

Cancel down 2 integers

Wonderful evening to all of you! My problem has to possible starting points. Well, not really, but getting to either one is no problem at all. So i got either a string in the format of "1920x1080" or simply the integers X = 1920 and Y = 1080. When I am done, I would like to have an output... (5 Replies)
Discussion started by: jakunar
5 Replies

5. Shell Programming and Scripting

integers, floats and text

I am using gawk in a dos shell in windows xp and want to read a datafile and reformat it. The datafile consists of columns of integers, floating point numbers and text strings. Each column is a fixed width and each column contains the same data type, eg all integers, all text. I am looking for a... (0 Replies)
Discussion started by: lookingfor help
0 Replies

6. Shell Programming and Scripting

Add non-integers using ksh

I would like to add 4.7 and 1.2. However I am unable to do this with expr. Any simple ideas (even using something other than expr)? Example: me> expr 4 + 1 5 me> expr 4.7 + 1.2 expr: 0402-046 A specified operator requires numeric parameters. (18 Replies)
Discussion started by: 2dumb
18 Replies

7. Shell Programming and Scripting

Unix Scripting Compare Integers

I have a file with the following: 87565 82155 102656 151 162 I want to write korn shell script that will read each line in a loop and remove any number that has less than 5 digits, e.g., 151 and 152. thank you, Keoki:confused: (4 Replies)
Discussion started by: keoki_mel
4 Replies

8. Programming

Using write() with integers in C

I'm trying to write an integer to a file using the write() function, but write() requires the parameter to be written to be a const void*. How would I go about doing this? also: using itoa() produces a " warning: implicit declaration of function 'itoa' " even though i have #included stdlib.h (2 Replies)
Discussion started by: h@run
2 Replies

9. Shell Programming and Scripting

integers in the if statement

hi, im trying to compare two variables in csh to put in an if statement, eg: set a = $firstnum set b = $secondnum if ($a -ge $b) echo $a But I get an error ("if: Expression syntax"). How can I make csh see my variables as integers? thanks in advance! (5 Replies)
Discussion started by: Deanne
5 Replies

10. Shell Programming and Scripting

Check if argument passed is an integers

How do I check if the argument passed to a script is an integer? I am writting a script that will take to integers and want to be able to check before I go on. I am using bourne shell. Thanks in advance (13 Replies)
Discussion started by: elchalateco
13 Replies
Login or Register to Ask a Question