Sponsored Content
Top Forums Shell Programming and Scripting Add and divide each numbers with the added number Post 302561500 by ahamed101 on Tuesday 4th of October 2011 10:01:15 AM
Old 10-04-2011
Try this...
Code:
#!/bin/bash

for file in *.dat
do
  out_file=$( echo ${file%%.*} ).div
  awk -v out_file=$out_file '
  { a=a+$0; b[++i]=$0} END{for(j=1;j<=i;j++){print b[j]/a > out_file} } ' $file
done

--ahamed
This User Gave Thanks to ahamed101 For This Post:
 

10 More Discussions You Might Find Interesting

1. AIX

How to replace many numbers with one number in a file

How to replace many numbers with one number in a file. Many numbers like 444565,454678,443298,etc. i want to replace these with one number (300).Please halp me out. (2 Replies)
Discussion started by: vpandey
2 Replies

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

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

4. Shell Programming and Scripting

Closest Number from a Range of Numbers

out of a range of numbers, how can i pick out the number that is the closest to any arbitrary/random number that a user supplies? say the range of numbers are between 1 - 90000. but that doesn't mean each number exist between 1 - 90000. the range of numbers could be for example: 1, 3, 4, 6,... (6 Replies)
Discussion started by: SkySmart
6 Replies

5. Shell Programming and Scripting

AWK print number of records, divide this number

I would like to print the number of records of 2 files, and divide the two numbers awk '{print NR}' file1 > output1 awk '{print NR}' file2 > output2 paste output1 output2 > output awl '{print $1/$2}' output > output_2 is there a faster way? (8 Replies)
Discussion started by: programmerc
8 Replies

6. Shell Programming and Scripting

Print numbers between two number ranges

Hi, I have a list.txt file with number ranges and want to print/save new all.txt file with all the numbers and between the numbers. == list.txt == 65936 65938 65942 && 65943 65945 ... (7 Replies)
Discussion started by: AK47
7 Replies

7. Shell Programming and Scripting

Is it possible to Divide a negative number in bash script

I am using a small script to divide some numbers in a given file and display the output in another file. I am getting the following error basename: invalid option -- '5' Try `basename --help' for more information. (standard_in) 1: syntax error The script is : #!/bin/bash for i in `cat... (4 Replies)
Discussion started by: kmnr877
4 Replies

8. Shell Programming and Scripting

Divide number of lines by the size of the same file. And create relational table.

I basically need to do what the title says. I have my text file. I'm still pretty new at this. At the moment I know that: 1. wc -l file.txt To get the number of lines. 2. ls -lh file.txt To get the file size. But I need to divide both numbers. Then I need to save the output in a... (7 Replies)
Discussion started by: PainMaker101
7 Replies

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

10. Shell Programming and Scripting

Divide the numbers in file

Dear ALL, I have sample file : 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 : minutes=$(( uptime/60%60 )) hours=$(( uptime/60/60%24 )) (3 Replies)
Discussion started by: gnulyn
3 Replies
Slurm API(3)					     Slurm front end node informational calls					      Slurm API(3)

NAME
slurm_free_front_end_info_msg, slurm_load_front_end, slurm_print_front_end_info_msg, slurm_print_front_end_table, slurm_sprint_front_end_table - Slurm front end node information reporting functions SYNTAX
#include <stdio.h> #include <slurm/slurm.h> void slurm_free_front_end_info_msg ( front_end_info_msg_t *front_end_info_msg_ptr ); int slurm_load_front_end ( time_t update_time, front_end_info_msg_t **front_end_info_msg_pptr, ); void slurm_print_front_end_info_msg ( FILE *out_file, front_end_info_msg_t *front_end_info_msg_ptr, int one_liner ); void slurm_print_front_end_table ( FILE *out_file, front_end_info_t *front_end_ptr, int one_liner ); char *slurm_sprint_front_end_table ( front_end_info_t *front_end_ptr, int one_liner ); ARGUMENTS
front_end_info_msg_ptr Specifies the pointer to the structure created by slurm_load_front_end. front_end_info_msg_pptr Specifies the double pointer to the structure to be created and filled with the time of the last front end node update, a record count, and detailed information about each front_end node. Detailed front_end node information is written to fixed sized records and includes: name, state, etc. See slurm.h for full details on the data structure's contents. front_end_ptr Specifies a pointer to a single front end node record from the front_end_info_msg_ptr data structure. one_liner Print one record per line if non-zero. out_file Specifies the file to print data to. update_time For all of the following informational calls, if update_time is equal to or greater than the last time changes where made to that information, new information is not returned. Otherwise all the configuration. job, node, or partition records are returned. DESCRIPTION
slurm_free_front_end_info_msg Release the storage generated by the slurm_load_front_end function. slurm_load_front_end Returns a ont_end_info_msg_t that contains an update time, record count, and array of records for all front end nodes. slurm_print_front_end_info_msg Prints the contents of the data structure describing all front end node records from the data loaded by the slurm_load_front_end function. slurm_print_front_end_table Prints to a file the contents of the data structure describing a single front end node record loaded by the slurm_load_front_end function. slurm_psrint_front_end_table Prints to memory the contents of the data structure describing a single front end node record loaded by the slurm_load_front_end function. RETURN VALUE
On success, zero is returned. On error, -1 is returned, and Slurm error code is set appropriately. ERRORS
SLURM_NO_CHANGE_IN_DATA Data has not changed since update_time. SLURM_PROTOCOL_VERSION_ERROR Protocol version has changed, re-link your code. SLURM_PROTOCOL_SOCKET_IMPL_TIMEOUT Timeout in communicating with SLURM controller. EXAMPLE
#include <stdio.h> #include <slurm/slurm.h> #include <slurm/slurm_errno.h> int main (int argc, char *argv[]) { int i; front_end_info_msg_t *front_end_info_ptr = NULL; front_end_info_t *front_end_ptr; /* get and dump some node information */ if ( slurm_load_front_end ((time_t) NULL, &front_end_buffer_ptr) ) { slurm_perror ("slurm_load_front_end error"); exit (1); } /* The easy way to print... */ slurm_print_front_end_info_msg (stdout, front_end_buffer_ptr, 0); /* A harder way.. */ for (i = 0; i < front_end_buffer_ptr->record_count; i++) { front_end_ptr = &front_end_buffer_ptr->front_end_array[i]; slurm_print_front_end_table(stdout, front_end_ptr, 0); } /* The hardest way. */ for (i = 0; i < front_end_buffer_ptr->front_end_count; i++) { printf ("FrontEndName=%s StateCode=%u ", front_end_buffer_ptr->front_end_array[i].name, front_end_buffer_ptr->front_end_array[i].node_state); } slurm_free_front_end_info_msg (front_end_buffer_ptr); exit (0); } NOTES
These functions are included in the libslurm library, which must be linked to your process for use (e.g. "cc -lslurm myprog.c"). Some data structures contain index values to cross-reference each other. If the show_flags argument is not set to SHOW_ALL when getting this data, these index values will be invalid. COPYING
Copyright (C) 2010 Lawrence Livermore National Security. Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). CODE-OCEC-09-009. All rights reserved. This file is part of SLURM, a resource management program. For details, see <http://www.schedmd.com/slurmdocs/>. SLURM is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. SLURM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. SEE ALSO
scontrol(1), slurm_get_errno(3), slurm_load_node(3), slurm_perror(3), slurm_strerror(3) Morris Jette December 2010 Slurm API(3)
All times are GMT -4. The time now is 08:15 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy