Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to read only numbers from file

Status
Not open for further replies.

ITadvice

IS-IT--Management
Jul 22, 2008
38
US
I am collecting data from text files that contain both text & numbers. I want to only get the numbers and not the text. What command do I use to only read in the numbers?
 
without knowing any specifics of your file:

Code:
while (<>){
   tr/0-9//cd; #deletes anything not in the list
   print;
}

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
This is kinda what the files are like. They contain mostly numbers but every so often there are rows of text (I think that the files were merged and they still contain the headers).

head head head
num num num
num num num
head head head
num num num
num num num

How can I use the tr function to only collect the numerical data?
 
Perl:
while (<>) {
   print if (/^[\s\d]+$/);
}
not tested

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top