Problem with calculations


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problem with calculations
# 1  
Old 12-19-2012
Problem with calculations

Code:
Code:
grep Quality abc.txt | awk -F"=" '{print $2}'

o/p is given as
Code:
70/70
49/70

I want in the below format (percentage format)
Code:
100%
70%


help me!!!!SmilieSmilieSmilie

---------- Post updated at 09:59 AM ---------- Previous update was at 09:57 AM ----------

Code:
Cell 01 - Address: BC:F6:85:4D:DB:97
Channel:9
Frequency:2.452 GHz (Channel 9)
Quality=70/70
Signal level=-22 dBm
Encryption key:on
ESSID:"AANCH_DLINK"
Cell 01 - Address: BC:F6:85:4D:DB:97
Channel:9
Frequency:2.452 GHz (Channel 9)
Quality=40/70
Signal level=-30 dBm
Encryption key:on
ESSID:"link_AP"


content of abc.txt

Last edited by Franklin52; 12-19-2012 at 03:23 AM.. Reason: Please use code tags for data and code samples
# 2  
Old 12-19-2012
try:
Code:
grep Quality abc.txt | awk -F"[=/]" '{printf( "%d%%\n", ($2/$3)*100) }'

This User Gave Thanks to rdrtx1 For This Post:
# 3  
Old 12-19-2012
thank you Smilie

---------- Post updated at 10:24 AM ---------- Previous update was at 10:23 AM ----------

sorry i forgot to include this question... :P
how do i replace the current o/p with the older one in abc.txt file...???
# 4  
Old 12-19-2012
try:
Code:
awk -F"[=/]" '/Quality/ {$0=sprintf( "%s=%d%%\n", $1,($2/$3)*100) }1' abc.txt

This User Gave Thanks to rdrtx1 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Loop doing calculations

Hello. I'm writing an awk script that looks at a .csv file and calculates the weighted grade for each student based on the scores and categories in the file. I am able to get the script to run the only issue however is that the same score for each student is the same. I'm self-teaching myself the... (1 Reply)
Discussion started by: Eric7giants
1 Replies

2. Shell Programming and Scripting

Output calculations

Attached are the is original output (zipped file) and a custom file using the awk code below in which the average reads per bait are calculated (average.txt) awk '{if(len==0){last=$4;total=$6;len=1;getline}if($4!=last){printf("%s\t%f\n", last,... (7 Replies)
Discussion started by: cmccabe
7 Replies

3. Shell Programming and Scripting

Number calculations

I'm writing a script that will read all the fields of a text file into an array(if they are numeric), while at the same time computing the minimum and maximum values from the file. After that I want to output the average of all the numbers in the array. The first problem I'm having is that many... (10 Replies)
Discussion started by: ksmarine1980
10 Replies

4. UNIX for Dummies Questions & Answers

Doing calculations with bc on one field

Hello, I have to turn: Apple Inc.:325,64:329,57 into Apple Inc.:325,64:329,57:3,93 3,93=329,57-325,64. My code: cat beurs.txt | sed 's/\(*\):\(*\),*\(*\):\(*\),\(*\)/\4\.\5-\2\.\3/' beurs.txt | bc| tr '.' ',' | sed 's/^-*,/0,/' > winstmarges.txt; paste -d: beurs.txt winstmarges.txt; rm... (5 Replies)
Discussion started by: ikke008
5 Replies

5. Shell Programming and Scripting

calculations in bash

HI i have following problem, i need to use split command to split files each should be cca 700 lines but i dont know how to inplement it in the scripts becasuse each time the origin file will be various size , any body got any idea cheers (2 Replies)
Discussion started by: kvok
2 Replies

6. UNIX for Dummies Questions & Answers

Date Calculations

I need to be able to use the current date and calculate 7 days ago to be stored in another variable to be passed to a file in my Unix shell script. I need the date in the following format: date '+%m/%d/%Y' or 05/16/2006 How do I calculate date minus 7 days or 1 week ago? (8 Replies)
Discussion started by: mitschcg
8 Replies

7. Shell Programming and Scripting

ksh, calculations using bc

hi all, was wondering if there is another way to do calculations in ksh scripts other than using bc ?? i am using a script to calculate average response time and my script errors out after running for a bit. e.g code i am using : averageTime=$(print "$totalTime / $numberOfEntries" |... (2 Replies)
Discussion started by: cesarNZ
2 Replies

8. UNIX for Dummies Questions & Answers

Time Calculations

I'm trying to have a loop print out statistics every X number of seconds. How can I add a specific number of seconds to a time variable and make a comparison? Thanks ahead of time. For example: startTime = `date +%H%M%S` currentTime = $startTime executeTime = startTime + X # X is equal... (5 Replies)
Discussion started by: Nysif Steve
5 Replies

9. Shell Programming and Scripting

problem doing the time calculations in shell.

I am trying to do a shell script to monitor if any files went through in the last hour. There is a script in cron that runs every sec checking to see if a file is there and ftp the file out of this folder. Now I just want to add a block of code that will check to see no files went in the last... (3 Replies)
Discussion started by: jonathan184
3 Replies

10. UNIX for Dummies Questions & Answers

Float calculations

As expr is used for integer calculations, which command is used for float calculations. (1 Reply)
Discussion started by: sharmavr
1 Replies
Login or Register to Ask a Question