calculating a number


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting calculating a number
# 1  
Old 09-05-2008
calculating a number

Hello all Smilie

I need some help; I'm running the sp_spaceused command on various tables and saving the output to a file. So, I have an input file that has 3 rows - each row has 7 columns. I would like to 1) sort the file on the 4th column, 2) take the 4th column in the first row and add 25% to that number - without doing the calculation on the other rows 3) put the new number in the 1st row of the input file

Here is an example of the input file
db1 tbl1 179877 11776 10868 776 132
db1 tbl2 150911 17692 17512 112 68
db1 tbl3 106651 3168 3004 24 140

Here is what I want the result to be:
db1 tb2 150911 22115 17512 112 68
db1 tbl1 179877 11776 10868 776 132
db1 tbl3 106651 3168 3004 24 140

Any suggestions on how to do this?

tia

Last edited by stonemonolith; 09-05-2008 at 04:10 PM.. Reason: misspelled word
# 2  
Old 09-05-2008
Try:

Code:
sort -k4,4nr file | awk '{if (NR==1) {$4 *= 1.25; } print; }'

# 3  
Old 09-05-2008
thanks. it works great!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

Calculating number of CPUs in Solaris-8

Hello, I have few old V210/V240, running Solaris-8. I am trying to find, number of physical CPUs, number of cores and number of virtual processors. psrinfo is giving me confusing status. It looks like, there are 2 physical CPUs, but psrinfo -p shows me just 1 bash-2.03$ psrinfo -v Status of... (4 Replies)
Discussion started by: ron323232
4 Replies

2. Shell Programming and Scripting

Grouping and Calculating

Hi All, I want to read the input file and store the output in the Output file. I pasted the sample Input and Output file below. Help me with this. Input file ================================= ITEM1 AAAAA 1 ITEM1 BBBBB 1 ITEM1 CCCCC 1 ITEM2 AAAAA 5 ITEM2 CCCCC 4... (1 Reply)
Discussion started by: humaemo
1 Replies

3. Shell Programming and Scripting

Performance of calculating total number of matching records in multiple files

Hello Friends, I've been trying to calculate total number of a certain match in multiple data records files (DRs). Let say I have a daily created folders for each day since the beginning of july like the following drwxrwxrwx 2 mmsuper med 65536 Jul 1 23:59 20150701 drwxrwxrwx 2 mmsuper... (1 Reply)
Discussion started by: EAGL€
1 Replies

4. Shell Programming and Scripting

Trouble calculating difference in number of days

Hi all, I have a requirement to calculate the difference of number of days of time stamp of a file and system date and if the difference is greater than 15 days it should prompt as previous month file otherwise current month file. Below is the code i used and it is working fine till now. (You... (2 Replies)
Discussion started by: Ravindra Swan
2 Replies

5. Shell Programming and Scripting

Calculating mean for samples 1-3 4-6 etc.

Hi. I have a LOOONG list of samples but I am not sure how to write the loop/script to calculate the mean... I normally use awk... ...................MEAN Sample1 25.82 40.61333 Sample1 47.6 Sample1 48.42 Sample2 54.03 54.12 Sample2 53.98 Sample2 54.35 etc..... I would like to... (4 Replies)
Discussion started by: danieladna
4 Replies

6. Shell Programming and Scripting

Calculating the epoch time from standard time using awk and calculating the duration

Hi All, I have the following time stamp data in 2 columns Date TimeStamp(also with milliseconds) 05/23/2012 08:30:11.250 05/23/2012 08:30:15.500 05/23/2012 08:31.15.500 . . etc From this data I need the following output. 0.00( row1-row1 in seconds) 04.25( row2-row1 in... (5 Replies)
Discussion started by: ks_reddy
5 Replies

7. Shell Programming and Scripting

Calculating number of records by field

Hi, I have CSV file which looks like below, i want to calulate number of records for each brand say SOLO_UNBEATABLE E and SOLO_UNBEATABLE F combined and record count is say 20 . i want to calculate for each brand, and here only first record will have all data and rest of record for the brand... (2 Replies)
Discussion started by: raghavendra.cse
2 Replies

8. Shell Programming and Scripting

Counting non empty fields and calculating with that number

Hello all, I have a problem with a skript of mine: My input has the following format 1,33296 transcript_id"ENSRNOT00000018629" 0 1,33296 0 0 transcript_id"ENSRNOT00000029014" 0 0,907392 transcript_id"ENSRNOT00000016905" 0,907392 0 transcript_id"ENSRNOT00000053370" 0 0... (0 Replies)
Discussion started by: DerSeb
0 Replies

9. Shell Programming and Scripting

calculating in MB

hi all, have got a ksh script which tries to monitor memory usage of app servers. i do a ps -0 rss -p <PID> to get the memory size in KB but when i divide by 1024 to convert to MB i dont know how to round it up ?? thanks in advance. (3 Replies)
Discussion started by: cesarNZ
3 Replies

10. UNIX for Dummies Questions & Answers

Calculating the Number of Rows and Average

Hi All I like to know how can we calculate the number of rows and the average of the values present in the file. I will not know what will be the rowcount, which will be dynamic in nature of the file. eg. 29 33 48 30 28 (6 Replies)
Discussion started by: pk_eee
6 Replies
Login or Register to Ask a Question