Divide the numbers in file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Divide the numbers in file
# 1  
Old 04-14-2017
Divide the numbers in file

Dear ALL,

I have sample file :
Code:
tx_bytes: 2422,
tx_packets: 13,
uptime: 16119,

tx_bytes: 2342,
tx_packets: 14,
uptime: 11009,

tx_bytes: 252,
tx_packets: 12,
uptime: 3113,

my formula :
Code:
minutes=$(( uptime/60%60 ))
hours=$(( uptime/60/60%24 ))

required output:
Code:
tx_bytes: 2422,
tx_packets: 13,
uptime: 4:28,

tx_bytes: 2342,
tx_packets: 14,
uptime: 3:3,

tx_bytes: 252,
tx_packets: 12,
uptime: 0:51,

Can you help me pls..

Last edited by vgersh99; 04-14-2017 at 12:56 PM.. Reason: code tags, please
# 2  
Old 04-14-2017
Not sure what you are after but this is longhand for one value:-
OSX 10.12.4, default bash terminal.
Code:
Last login: Fri Apr 14 16:52:28 on ttys000
AMIGA:barrywalker~> uptime=16119
AMIGA:barrywalker~> minutes=$(( uptime/60 )) 
AMIGA:barrywalker~> echo $minutes
268
AMIGA:barrywalker~> hours=$(( minutes/60 )) 
AMIGA:barrywalker~> echo $hours
4
AMIGA:barrywalker~> minutes=$(( minutes - ( hours * 60 ) ))
AMIGA:barrywalker~> echo $minutes
28
AMIGA:barrywalker~> uptime="$hours:$minutes"
AMIGA:barrywalker~> echo $uptime
4:28
AMIGA:barrywalker~> _

# 3  
Old 04-14-2017
Code:
awk '$1=="uptime:" {$2=sprintf("%02d:%02d,", $2/60/60%24, $2/60%60) }1' myFile

This User Gave Thanks to vgersh99 For This Post:
# 4  
Old 04-14-2017
Thanks for vgersh99

Code:
[root@localhost ~]# ./forum.sh
tx_bytes: 2422,
tx_packets: 13,
uptime: 04:28,

tx_bytes: 2342,
tx_packets: 14,
uptime: 03:03,

tx_bytes: 252,
tx_packets: 12,
uptime: 00:51,
[root@localhost ~]#


Last edited by Don Cragun; 04-14-2017 at 09:29 PM.. Reason: Add CODE tags again.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to divide/expand first digit to show some numbers

Hello to everyone, I have this complex problem and I don't how to do it. I'm not sure if awk could be a good choice to do it or could be easiest in bash or perl. A kind of introduction would be: - I have a digit, lets say 3. - I can expand/spread out the digit 3 to cover all possible... (7 Replies)
Discussion started by: Ophiuchus
7 Replies

2. UNIX for Dummies Questions & Answers

To divide file

We have large log files, and we need to extract last four hours lines only, Please let us know the command. Thanks, Saurau. (1 Reply)
Discussion started by: saurau
1 Replies

3. 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

4. UNIX for Dummies Questions & Answers

divide the file into multiple files based on the city name

Hi, I have a file abc.dat. It contains the fileds of empid, empname, empcity. each city contains 10 records. i want to create the city file and pass the same city records into the file. I don't know the city names. In unix using awk command how can we do? abc.dat: 1 john delhi 2... (2 Replies)
Discussion started by: raghukreddy.ab
2 Replies

5. Shell Programming and Scripting

Add and divide each numbers with the added number

Hi All, I am stuck with this problem. I have some 100000 (.dat) 1.dat, 2.dat,3.dat etc until 100000.dat files which look like this: 1.dat 1 2 3 4 0.99 4.54 All my files 1.dat until 100000.dat look the same but with different numbers. I have to first add all the numbers in each... (1 Reply)
Discussion started by: shoaibjameel123
1 Replies

6. 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

7. Shell Programming and Scripting

Divide numbers into intervals

divide input values into specified number (-100 or -200) according to the key (a1 or a2 ....) For ex: if we give -100 in the command line it would create 100 number intervals (1-100, 100-200, 200-300) untill it covers the value 300 in a1. Note: It should work the same even with huge numbers... (3 Replies)
Discussion started by: ruby_sgp
3 Replies

8. Shell Programming and Scripting

Divide the file into several Variable

I have a file, let's say X BTS 0 UNLOCKED ENABLED NONE TRX 0 UNLOCKED ENABLED NONE TRX 1 UNLOCKED ENABLED NONE BTS 1 UNLOCKED ENABLED NONE TRX 0 UNLOCKED ENABLED NONE... (4 Replies)
Discussion started by: amaulana
4 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

divide a single file with different Weboffercodes into different files with each of o

Here is the format of my file; I do not have the delimiter in the file for the data to be separated. Each line in the file is in the following format. File contains the data of different WebOfferCodes Item Code | Account Number | Card Number | Source code | WebOfferCode 12digits | 10... (4 Replies)
Discussion started by: enigma_83
4 Replies
Login or Register to Ask a Question