Extracting numeric from string

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Extracting numeric from string
# 1  
Old 08-02-2009
Extracting numeric from string

I have a file whose contents are:
$ cat file1

sed 's/[^0-9]//g' file1 > file2

$cat file1

Is there any way by which i can work on same file and write o/p to the same file instead of using file2

Last edited by vjasai; 08-02-2009 at 11:06 AM..
# 2  
Old 08-02-2009
use Perl:

perl -i~ -ple'tr/[0-9]//dc' file1

# 3  
Old 08-02-2009
GNU sed supports in place editing.
# 4  
Old 08-02-2009
or with tee:

tr -dc '[0-9
]' < file1 | tee file1

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extract all first numeric character from a string

Hello, I have a file of strings a below:- 4358RYFHD9845 28/COC/UYF984 9834URD 98HJDU I need to extract all the first numeric character of every sting as follows:- 4358 28 9834 thanks to suggest ASAP Regards, Jasi Use code tags, thanks. (7 Replies)
Discussion started by: jassi10781
7 Replies

2. Programming

C++ Get text and numeric value from a string

I have a string opt="row234" I want to put "row" in a string and 234 in an int. In general it should be opt="textnum" I want to store text in a string and num in an int. (6 Replies)
Discussion started by: kristinu
6 Replies

3. Shell Programming and Scripting

check if a string is numeric

I checked all the previous threads related to this and tried this. My input is all numbers or decimals greater than zero everytime. I want to check the same in the korn shell script. Just validate the string to be numeric. This is what I am doing. var="12345" if ) -o "$var" !=... (14 Replies)
Discussion started by: megha2525
14 Replies

4. Shell Programming and Scripting

How to parse a numeric string without any delimiters?

Hi , I have a number say 12345001 which needs to be parsed. Its a number that has no delimiters.I have to read the last three digits and then the rest of digits irrespective of the total length of the number. The digits then have to be swapped and changed to a fixed length. The fillers to be... (10 Replies)
Discussion started by: Sheel
10 Replies

5. Shell Programming and Scripting

Extracting information and creating numeric values using awk

I have some variables containing for example m02-npt02-sr40-syn-dv0p01-16x12drw m02-npt02-sr40-syn-dv0p02-16x12drw m02-npt02-sr40-dv0p03-syn-16x12drw I want to extract the dv entry for example dv0p01 dv0p02 dv0p03 Then I want to convert to a numeric, the p specifies the... (5 Replies)
Discussion started by: kristinu
5 Replies

6. Programming

check the given string is numeric or not.

Hi, how to check the given string is numeric or not , without converting ( using strtol...). for ex: if string is C01 - non-numeric data if string is 001 - numeric data TIA (11 Replies)
Discussion started by: knowledge_gain
11 Replies

7. Shell Programming and Scripting

numeric string and length

given a string passed to a program that supposed to be numeric and of a certain length say 8 digits - so say for e.g. need to verify this 01234567 How would I parse this string to validat it meet requirements I tried to use * | sed /\(\{8})/ Thanks in advance (1 Reply)
Discussion started by: dragrid
1 Replies

8. Shell Programming and Scripting

problem in comparing numeric with string

Hi all, I am having a problem in comparing numeric value with string. I have a variable in my script which gets the value dynamically. It can be a numeric value or a string. I have to do separate task based on its value numeric or sting variable VARIABLE. I grep FILE_COUNT and obtained... (7 Replies)
Discussion started by: naren_0101bits
7 Replies

9. Shell Programming and Scripting

Extracting a string from one file and searching the same string in other files

Hi, Need to extract a string from one file and search the same in other files. Ex: I have file1 of hundred lines with no delimiters not even space. I have 3 more files. I should get 1 to 10 characters say substring from each line of file1 and search that string in rest of the files and get... (1 Reply)
Discussion started by: mohancrr
1 Replies

10. Shell Programming and Scripting

Convert string to numeric

Hi, I have read some figures from a text file by getting the position and wish to do some checking, but it seem like it won't work. eg. my figure is 0.68 it still go the the else statement, it seems like it treat it as a text instead of number. Anybody can Help ? Thanks. # only... (3 Replies)
Discussion started by: kflee2000
3 Replies
Login or Register to Ask a Question