grep numbers


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers grep numbers
# 1  
Old 07-23-2008
grep numbers

Hello,

I'm trying to grep for digits surrounded by non digits and I'm obviously misinformed. Could someone help me get this sorted out

here is what I have that is not working

grep -ho '\D([0-9]\{11\})\D' *.txt
# 2  
Old 07-24-2008
Example for input and desired output needed, ty.
# 3  
Old 07-24-2008
\D is a Perl regex extension and is not supported in grep in general.

Code:
grep -ho '[^0-9][0-9]\{11\}[^0-9]' *.txt

# 4  
Old 07-24-2008
thank you

though that not quite what I'm looking for here are some examples

input examples:
some text I wrote +90123456789 and some more text
new line with different numbers 1234567890 notice only 10 digits
yet another line '11234567890'

output desired
+90123456789
1234567890
11234567890

also note that I do want the 10 digit number as well

thanks again

mcgrailm
# 5  
Old 07-24-2008
grep -ho '[+0-9]\{10,12\}' some.txt
# 6  
Old 07-25-2008
To really enforce the requirement that the matches have to be adjacent to non-number characters, you could egrep -o '[^0-9][0-9]+[^0-9]' | grep -o '[0-9]*' but given your usage scenario, I guess you didn't mean that the matches always have to be adjacent to non-number characters ... in which case just simply grepping for numbers like Ikon suggests will work excellently. (By definition, wildcards like \{10,12\} and * are greedy, so will match as many numbers as possible.)
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Please help on UNIX grep command for numbers

I have a list of files like below, Do we have grep command to find files? If i grep 03874 it should display the file 3874, Grep command should ignore 0 at the beginning. There could be more many leading 0's in filename. $ ls -ltr total 5 -rw-r--r-- 1 mqm mqm 15 Feb 19 17:07 4769... (3 Replies)
Discussion started by: prince1987
3 Replies

2. UNIX for Advanced & Expert Users

Grep for a line containing only 5 numbers

How would you grep for a line containing only 5 numbers? Something like this. 10 2 12 1 13 (4 Replies)
Discussion started by: cokedude
4 Replies

3. UNIX for Dummies Questions & Answers

Grep for a range of numbers?

I am trying to extract specific information from a large *.sam file (it's originally 28Gb). I want to extract all lines that are on chr3 somewhere in the range of 112,937,439-113,437,438. Here is a sample line from my file so you can get a feel for what each line looks like: seq.4 0 ... (8 Replies)
Discussion started by: genGirl23
8 Replies

4. Shell Programming and Scripting

grep for a range of numbers

Dear Friends, I want to know how to grep for the lines that has a number between given range(start and end). I have tried the following sed command. sed -n -e '/20030101011442/,/20030101035519/p' However this requires both start and end to be part of the content being grepped. However... (4 Replies)
Discussion started by: tamil.pamaran
4 Replies

5. UNIX for Dummies Questions & Answers

grep to get line numbers

I know if i use grep -n that the output will have the lines numbered but is there a way to grep the actually line number. so like this grep -n "one" /usr/dict/numbers 1:one 21:twenty-one 31:thirty-one 41:forty-one 51:fifty-one 61:sixty-one 71:seventy-one 81:eighty-one 91:ninety-one ... (1 Reply)
Discussion started by: alindner
1 Replies

6. Shell Programming and Scripting

grep a pattern with line numbers.

I have a txt file with more than 10000 lines. There is a unique pattern which is scattered into the file. it starts with @9 and it has 15 characters. i need to grep them and display along with line numbers. Eg: File - Test1 test message.... .... .. .. @9qwerty89 ...test message... (8 Replies)
Discussion started by: abinash
8 Replies

7. UNIX Desktop Questions & Answers

grep numbers

Hi all, I am new to unix and struggling to do the below I have few lines in a xml <title>abc:1</title> <description>abc:2</description> <language>abc:3</language> Is it possible to extract only the entire word like abc:1 abc:2 abc:3 instead of the entire line into a new file . Kindly... (3 Replies)
Discussion started by: umapearl
3 Replies

8. UNIX for Dummies Questions & Answers

Using grep on a range of numbers

Hi im new to unix and need to find a way to grep the top 5 numbers in a file and put them into another file. For example my file looks like this abcdef 50000 abcdef 45000 abcdef 40000 abcdef 35000 abcdef 30000 abcdef 25000 abcdef 20000 abcdef 15000 abcdef 10000 and so on... How can... (1 Reply)
Discussion started by: ProgChick2oo9
1 Replies

9. Shell Programming and Scripting

grep for non numbers

Hi, I want to find out whether a string contains non numbers and + and - example : Str="0005000A" - It contains A Str="0005000+" - No problem What I have done is , echo $Str | grep I will have to list out all non numeric characters... (6 Replies)
Discussion started by: shihabvk
6 Replies

10. Shell Programming and Scripting

grep numbers range

I want to grep a range of numbers in a log file. My log file looks like this: 20050807070609Z;blah blah That is a combination of yr,month,date,hours,minutes,seconds. I want to search in the log file events that happened between a particular time. like between 20050807070000 to 20050822070000... (1 Reply)
Discussion started by: azmathshaikh
1 Replies
Login or Register to Ask a Question