Search only numbers in a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Search only numbers in a file
# 1  
Old 06-02-2011
Search only numbers in a file

Hello team,

Suppose I have a file named that has following content:

Code:
abc123
1897
msxi12
------------
########
((((( rapjagc )))))))
34229
xxxxxxxxxxxx
@@@536

I need those lines that contain only numbers from this file.
means -- it should eliminate alphanumber, special characters and characters.

like from above example I need these lines:
Code:
1897
34229



Please help me on this

Last edited by radoulov; 06-02-2011 at 05:06 AM.. Reason: Code tags.
# 2  
Old 06-02-2011
Code:
grep -xE '[0-9]+' infile

Use the POSIX grep (/usr/xpg4/bin/grep) if you're on Solaris.

Last edited by radoulov; 06-02-2011 at 05:26 AM..
# 3  
Old 06-02-2011
Through sed..
Code:
sed '/^[0-9][0-9]*$/!d' inputfile > outfile

# 4  
Old 06-02-2011
Code:
egrep ^[0-9]+$ infile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Search for columns with numbers greater than 70

This helped get me started. https://www.unix.com/unix-for-dummies-questions-and-answers/157026-need-command-search-numbers-greater-than-3000-a.html This is the command I am using. I am trying to find numbers greater than 70 in column 5. I do not know if it is getting confused because there... (6 Replies)
Discussion started by: cokedude
6 Replies

2. Shell Programming and Scripting

Adding (as in arithmetic) to numbers in columns in file, and writing new file with new numbers

Hi again. Sorry for all the questions — I've tried to do all this myself but I'm just not good enough yet, and the help I've received so far from bartus11 has been absolutely invaluable. Hopefully this will be the last bit of file manipulation I need to do. I have a file which is formatted as... (4 Replies)
Discussion started by: crunchgargoyle
4 Replies

3. Shell Programming and Scripting

Streamline script to search for numbers in a certain range

Hello all, I need help making a script run faster since I have a huge file to sift through. The file I am running my script on looks like this: 1 -1.9E+001 -1.8E-001 1.5E+001 3.32E+001 2 -1.7E+001 -1.0E-002 1.2E+001 6.37E+001 3 -1.5E+001 -3.8E-006 6.7E+001 4.81E+001 The... (12 Replies)
Discussion started by: butson
12 Replies

4. Shell Programming and Scripting

How to search for numbers greater than x?

I have a file with multiple fields, example below File 1: Field 1|Field 2|Field 3|Field 4|Field 5|Field 6|Field 7|100 Field 1|Field 2|Field 3|Field 4|Field 5|Field 6|Field 7|101 Field 1|Field 2|Field 3|Field 4|Field 5|Field 6|Field 7|102 Field 1|Field 2|Field 3|Field 4|Field 5|Field... (4 Replies)
Discussion started by: castrojc
4 Replies

5. Shell Programming and Scripting

Search within file1 numbers from list in file2

Hello to all, I hope somebody could help me with this: I have this File1 (real has 5 million of lines): Number Category --------------- -------------------------------------- 8734060355 3 8734060356 ... (6 Replies)
Discussion started by: Ophiuchus
6 Replies

6. Shell Programming and Scripting

How search a list of numbers from a file

Hi Guys! I have two input files. I want to search each of the numbers (studentid) on inputfile1 from inputfile2 and print the studentid and section that are listed from inputfile1. See the desired output below. inputfile1.txt: studentid 261054689 266605695 269826642 264966513... (2 Replies)
Discussion started by: pinpe
2 Replies

7. Shell Programming and Scripting

the smallest number from 90% of highest numbers from all numbers in file

Hello All, I am having problem to find what is the smallest number from 90% of highest numbers from all numbers in file. I am having file with thousands of lines and hundreds of columns. I am familiar mainly with bash but I am open to whatever suggestion witch will lead to the solutions. If I... (11 Replies)
Discussion started by: Apfik
11 Replies

8. UNIX for Dummies Questions & Answers

need a command to search for numbers greater than 3000

i have a file contains: 13213,A,300 3423,C,200 5563,A,201 3000,A,400 3000,A,402 3000,A,206 3000,A,303 3000,A,200 4233,N,204 i need to search for numbers in the first column are greater than 3000? i have another issue if you can help me? if i want to search in the second or the... (7 Replies)
Discussion started by: takyeldin
7 Replies

9. Shell Programming and Scripting

read numbers from file and output which numbers belongs to which range

Howdy experts, We have some ranges of number which belongs to particual group as below. GroupNo StartRange EndRange Group0125 935300 935399 Group2006 935400 935476 937430 937459 Group0324 935477 935549 ... (6 Replies)
Discussion started by: thepurple
6 Replies

10. Shell Programming and Scripting

Shell script to search through numbers and print the output

Suppose u have a file like 1 30 ABCSAAHSNJQJALBALMKAANKAMLAMALK 4562676268836826826868268468368282972982 2863923792102370179372012792701739729291 31 60... (8 Replies)
Discussion started by: cdfd123
8 Replies
Login or Register to Ask a Question