Need to extract only decimal numbers for a glob of text [SOLVED]
If you have a look at this thread, you'll see that users have been posting the output a script which are numbers that range from 2 to 5 decimal places. If I dump this entire thread to txt file, how can I:
1) Delete everything except for numbers of the following formats (where 'x' is a digit and '.' is a decimal point)?
2) Format the output to be one target per line?
x.xx
x.xxx
x.xxxx
x.xxxxx
xx.xx
xx.xxx
xx.xxxx
xx.xxxxx
I have experimented with some sed strings but am not making any traction. Perhaps your perl or awk ninjas have a good solution?
EDITED PER MOD REQUEST REMOVING LINK TO FILE AND PASTING IT HERE:
Code:
San2ban wrote:
8.09943
Surprised!. I will remove some bloat and try again
I am overbloated and got a 8.73; try the opposite
Offline
Report Quote
#352012-03-04 7:42 am
Blµb
Member
Registered: 2008-02-10
Posts: 174
(a) 8.38748
(b) 8.39183
(b) Includes my ~/bin which contains a set of scripts to ease my life. And cbmc, a huge binary, actually a statistical outlier even, since it's 4.6M.
How about taking a look at binaries and scripts seperately? Since scripts, for example, lack all the ELF format overhead their executing binaries have...
root@blubpc ~ # cat > /tmp/filter.sh << EOF
#!/bin/sh
if head "\$1" | grep -q '^#!'; then
stat -c '%s' "\$1"
else
stat -c '%s' "\$1" >&2
fi
EOF
root@blubpc ~ # chmod +x /tmp/filter.sh
root@blubpc ~ # find {,/usr}/{s,}bin /lib /boot /etc /home/blub/bin -type f -executable -exec /tmp/filter.sh '{}' "%s" ';' > /tmp/filtered_scripts 2> /tmp/filtered_bins
root@blubpc ~ # T1=$(cat /tmp/filtered_bins | awk '{t+=$1} END {print t}')
root@blubpc ~ # T2=$(cat /tmp/filtered_scripts | awk '{t+=$1} END {print t}')
root@blubpc ~ # echo $T1 $T2
868139304 30871849
root@blubpc ~ # cat /tmp/filtered_bins | awk -v t=$T1 '{p=$1/t; h += -p*log(p)/log(2)} END {print h}'
8.25136
root@blubpc ~ # cat /tmp/filtered_scripts | awk -v t=$T2 '{p=$1/t; h += -p*log(p)/log(2)} END {print h}'
6.06017
root@blubpc ~ # echo sanity check, the following should equal b=8.39183
sanity check, the following should equal b=8.39183
root@blubpc ~ # cat /tmp/filtered_bins /tmp/filtered_scripts | awk -v t=$[T1 + T2] '{p=$1/t; h += -p*log(p)/log(2)} END {print h}'
8.39183
root@blubpc ~ # cat /tmp/filtered_bins | awk -v t=$[T1 + T2] '{p=$1/t; h += -p*log(p)/log(2)} END {print h}'
8.01669
root@blubpc ~ # cat /tmp/filtered_scripts | awk -v t=$[T1 + T2] '{p=$1/t; h += -p*log(p)/log(2)} END {print h}'
0.375133
Not really what I was expecting O.o
You know you're paranoid when you start thinking random letters while typing a password.
A good post about vim
Python has no multithreading.
Offline
Report Quote
#362012-03-04 8:40 am
azleifel
Member
From: St Evenage, UK
Registered: 2007-10-28
Posts: 475
Email
8.72211
---------- Post updated at 07:45 PM ---------- Previous update was at 07:12 PM ----------
I'm getting closer but still no cigar:
Code:
% grep '[0-9]\.[0-9][0-9]' unixness_thread.txt | sed 's/[^0-9.]*//g'
Last edited by graysky; 12-24-2012 at 08:54 AM..
Reason: mod request/just provided a sample
How can i devide decimal numbers?
I am getting this kind of error:
line 18: 200.2/40.234: syntax error in expression (error token is ".2/40.234")
What can i do to work around this problem?
Thanks for any advice. (4 Replies)
Hi friends
How can I use "for loop" for decimal numbers?
ex: 0.1 < x < 0.6
I used this commands but does'nt work.
LIMIT=0.6
for ((x=0.1; x<=LIMIT; x++))
do
-
-
-
done
Many thanks (1 Reply)
Im trying to compare two numbers with decimals but its not working as expected.
a=1
b=1.1
if
then echo "equal"
fi
When I do this it says that the numbers are equal. Ultimately Im using -le and -ge in the if statements but I tested with -eq for simplicity.
Any way to make this... (3 Replies)
Hello...
I am new to unix and I am wondering if in a C-shell script , Are we supposed to use only whole numbers........ for example..if a program needs to calculate the average of some numbers........
@ avg = (($1 +$2 + $3)/3)) is returning a whole number.........How can a decimal be... (7 Replies)
Just wondering if someone could assist me with shell script I'm trying to write. I need to read the final column of a text file (shown below) and workout what the average number is. The text file will have a variable number of lines, I just want the script to pull out the values in the final field... (14 Replies)
Hi experts,
My number output has somehting like below
filename /temp
0.23
10.23
How do i put a condition to the above numbers?
e.g
if then
the . seem to give me problems. Pls help.
thanks
---------- Post updated at 05:25 PM ---------- Previous update was at 05:23 PM... (9 Replies)
Hi,
I have a small problem with my script. I have everything in order but it doesnt seem to compare anything less than 1 correctly. If the input is more than 1, then the results is correct.
If the input is 0.xxx (anything) it returns erroneous results. Pls help
input=0.12
if ; then
... (7 Replies)
Hello All,
I need to extract lines from a file that contains ALPHANUMERIC and the length of Alphanumeric is set to 16. I have pasted the sample of the lines from the text file that I have created.
My problem is that sometimes 16 appears in other part of the line. I'm only interested to... (14 Replies)
For numbers between 0 and 1 the below logic is not working.
Output of above shall be "correct" but its echoing "incorrect".Kindly suggest
a=.1
if
then
echo correct
else echo incorrect
fi
Video tutorial on how to use code tags in The UNIX and Linux Forums. (3 Replies)
Hi!
I found and then adapt the code for my pipeline...
awk -F"," -vOFS="," '{printf "%0.2f %0.f\n",$2,$4}' xxx > yyy
I add -F"," -vOFS="," (for input and output as csv file) and I change the columns and the number of decimal...
It works but I have also some problems... here my columns
... (7 Replies)