How to strip non numerical data out of file?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to strip non numerical data out of file?
# 1  
Old 01-08-2007
How to strip non numerical data out of file?

Hi,

How can I remove all non numerical data from line, so I don't want to delete the line but to have only the numbers.

e.g.:
#########
123
aaa124
125bbb
126
127
#########

So I want all the leading and trailing non numerical stuff(letters/white space/tabs anything else except [0-9]) stripped.

So from above I would get:
#########
123
124
125
126
127
#########

Thanks a lot for your help!
//Juha
# 2  
Old 01-08-2007
Code:
tr -d "[:alpha:][:punct:]" < inputfile


Last edited by tayyabq8; 01-08-2007 at 11:12 AM.. Reason: Misunderstood requirement earlier
# 3  
Old 01-08-2007
Try this :
Code:
sed 's/[^[:digit:]]*//g' inputfile


Jean-Pierre.
# 4  
Old 01-08-2007
Thanks! Either of the did not work though:

/tmp]>> tr -d [:digit:] < inputfile

aaa
bbb


So I get only the stuff I don't want.

/tmp]>> sed 's/[^[:digit:]]*//g' inputfile



I get nothing at all.
# 5  
Old 01-08-2007
I have edited my earlier post, check that if it works.
# 6  
Old 01-08-2007
Yep it's getting closer Smilie still need to get the trailing and leading white spaces/tabs removed.
# 7  
Old 01-08-2007
Ok this seems to do the trick:
tr -d "[:alpha:][:punct:][:blank:]" < inputfile

Thanks a lot for your help guys!
/Juha

Last edited by vino; 01-08-2007 at 11:40 AM.. Reason: Disable smilies in text
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Divide a numerical data column by a variable

Hello, I have two files, f1 and f2. f1 has 5 columns like so: a b c d 154 e f g h 365 ..... f2 has two columns, the first column contains the name of the above file and second column contains a constant which is to be used for division. e.g. file1 56 I want to divide the 5th... (2 Replies)
Discussion started by: Gussifinknottle
2 Replies

2. Shell Programming and Scripting

how to extract data from numbered files using linux in the numerical order-

Hi experts, I have a list of files containing forces as the only number as follows. Force1.txt Force2.txt Force3.txt Force4.txt Force5.txt . . . . . . . . . Force100.txt I want to put all the data(only a number ) in these forces files in the file with the same order like 1,2,3 ..100 .... (2 Replies)
Discussion started by: hamnsan
2 Replies

3. Shell Programming and Scripting

strip csv file

Hi everyone, I hope someone can help me: i am trying to get some info from a csv file, after i awk the column i need , i made a selection and output it in a file. now i need to get a list from this file, but i stuck with some fields. basically i have a text file with next data: 3... (3 Replies)
Discussion started by: lostym
3 Replies

4. Shell Programming and Scripting

script to sort a string of numerical data in set fields

So, I will be working with someone and basically we are trying to build a form that is submitted most likely via the web and the data is just a string of numbers. like: 19383882872201110929282821818182827349190102837364718191001932873711 Now, each number is part of a numerical value of... (4 Replies)
Discussion started by: tlarkin
4 Replies

5. Shell Programming and Scripting

Reading Numerical Binary Data using KSH

Hi, I've searched and couldn't find anyone else with this problem. Is there anyway (preferably using ksh - but other script languages would do) that I can read in binary float data into a text file. The data (arrays from various stages of radar processing) comes in various formats, but mainly... (3 Replies)
Discussion started by: Jonny2Vests
3 Replies

6. Programming

Adding files of numerical data

Hi I was hoping that maybe someone could help me with a small piece of C code. I have a number of files, which are all of similar layout ie. three lines of text and 5-6 columns of numerical data. I need to add each of the elements of the second column in one file to their counterparts in the second... (17 Replies)
Discussion started by: Boucho
17 Replies

7. UNIX for Dummies Questions & Answers

How to strip the contants from a file

Hi, I have some EDI data which 830, 862 and 997. Here is the sample data: ISA~00~ ~00~ ~ZZ~F159B ~ZZ~U1CAD ~051215~184 3~U~00200~000011432~0~P~< GS~FA~TC11A~U1CAD~051215~1843~000011432~X~002002 ST~997~0001 AK1~SH~1168 AK2~856~11680001 AK5~A... (2 Replies)
Discussion started by: isingh786
2 Replies

8. Shell Programming and Scripting

How to strip apostrophe from a file

I am trying to remove or replace various extraneous characters from a file so that subsequent processes work correctly. The characters that is giving me trouble is the apostrophe '. The command I 'm trying is sed 's/\'//g' ${IN_WRK_DIR}/file1 > ${IN_WRK_DIR}/file2 in a Korn script on HP... (8 Replies)
Discussion started by: aquimby
8 Replies
Login or Register to Ask a Question