Sponsored Content
Top Forums Shell Programming and Scripting awk to get lowest & store value from another file... Post 302953565 by malcomex999 on Sunday 30th of August 2015 04:56:31 AM
Old 08-30-2015
awk to get lowest & store value from another file...

I have two files. One small stores and one with large stores like below...

Small-stores.txt
Code:
Store	Code	Excess Stock
K76	23812	17
K50	23812	6
K16	23812	4
K22	23812	3
K69	23812	3
K76	23813	10
K50	23813	7
K16	23813	6
K69	23813	4
K22	23813	3
K69	23814	10
K76	23814	6
K16	23814	4
K50	23814	4
K22	23814	3
K76	30002	4
K16	30002	2
K69	30002	2
K22	30002	1

Large-stores.txt
Code:
Store	Code	Excess Stock
K15	23812	4
K47	23812	4
K48	23812	13
K53	23812	3
k03	23812	2
K17	23813	19
k03	23813	7
K46	23813	7
K78	23813	17
K24	23813	4
K30	23814	6
K60	23814	6
k90	23814	5
K17	23814	4
K44	23814	4
K26	30002	2
k03	30002	-5
K05	30002	-6
K09	30002	-5
K13	30002	-2
K14	30002	-2
K15	30002	20
K71	30002	-1
K78	30002	-1
K87	30002	-3
k90	30002	-1

what i want to do is that, i want to transfer the excess stocks i have from small stores to large stores.

expected output...
Code:
Store	Code	Excess	Transfer-To Transfer-qty
K76	23812	17	k03	8
K50	23812	6	k53	6
K16	23812	4	k47	4
K22	23812	3	k15	3
K69	23812	3	null	null
K76	23813	10	k24	6
K50	23813	7	k03	3
K16	23813	6	k46	3
K69	23813	4	null	null
K22	23813	3	null	null
K69	23814	10	k44	6
K76	23814	6	k17	6
K16	23814	4	k90	4
K50	23814	4	k60	4
K22	23814	3	k30	3
K76	30002	4	k90	4
K16	30002	2	k87	2
K69	30002	2	k78	2
K22	30002	1	k71	1

To make it clear...
1. I want to get the biggest excess stock from small-stores.txt file and transfer it to smallest excess stocks in large-store.txt file. I can go up to positive 10 in excess stock in large-stores.txt file and minimize the excess stocks in small-stores.txt file to zero.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed & awk--get section of file based 2 params

I need to get a section of a file based on 2 params. I want the part of the file between param 1 & 2. I have tried a bunch of ways and just can't seem to get it right. Can someone please help me out.....its much appreciated. Here is what I have found that looks like what I want....but doesn't... (12 Replies)
Discussion started by: Andy Cook
12 Replies

2. UNIX for Dummies Questions & Answers

Finding the lowest sequenced file in a directory?

Hello, I have three files in a directory: 1_700_123456.lst 1_701_123456.lst 1_702_123456.lst I am trying to use a command via ksh that will list the file that has the lowest number in the second node and put that to a file. In the example above, it would put 1_700_123456.lst... (2 Replies)
Discussion started by: stky13
2 Replies

3. Shell Programming and Scripting

Getting all the files modified today & store the names in a variable as , separated

Hi all, I have a question. I have a folder. I want to find the list of files that are modified today and store all those file names in a variable as comma separated values. I thought of using "find . -mtime 0" command to find the list of files modified today. Also to get those values of file... (10 Replies)
Discussion started by: ananthi_ku
10 Replies

4. Shell Programming and Scripting

Korn Shell - Finding lowest number of a file.

I'm writing a KSH script that will get a file on the command line (such as input.txt), and in this file there is on number per line. The program needs to take the file, read each and determine the lowest number in the file. I currently have a while loop setup that will correctly out put every... (8 Replies)
Discussion started by: denyal
8 Replies

5. Shell Programming and Scripting

SED/AWK file read & manipulation

I have large number of data files, close to 300 files, lets say all files are same kind and have extension .dat , each file have mulitple lines in it. There is a unique line in each file containing string 'SERVER'. Right after this line there is another line which contain a string 'DIGIT=0',... (4 Replies)
Discussion started by: sal_tx
4 Replies

6. Shell Programming and Scripting

Parse text file in shell & store to variable

Hi, I need to parse a simple text file like below and store the word that starts with BR* to a variable say $BRno. I need to do this in sh script. NOTE: the length of the numbers following BR is in constant. And there is only 1 BRXXX in a file at a given time. .txt file: BR276828... (1 Reply)
Discussion started by: script2010
1 Replies

7. Shell Programming and Scripting

copying file information using awk & grep

Hi, TASK 1: I have been using this code to print the information of files kept at "/castor/cern.ch/user/s/sudha/forPooja" in some text file name FILE.txt. rfdir /castor/cern.ch/user/s/sudha/forPooja | grep data | awk '{print "rfio:///castor/cern.ch/user/s/sudha/forPooja/"$9}' > FILE.txt ... (6 Replies)
Discussion started by: nrjrasaxena
6 Replies

8. Shell Programming and Scripting

ksh program that finds the lowest number in a .txt file

i am having a problem finding the lowest number after punching in a bunch of numbers in the .txt file but its probably the way i have the code set up. help please! (4 Replies)
Discussion started by: tinsteer
4 Replies

9. UNIX for Dummies Questions & Answers

Awk, highest and lowest value of a column

Hi again! I am still impressed how fast I get a solution for my topic "average specific column value awk" yesterday. The associative arrays in awk work fine for me! But now I have another question for the same project. Now I have a list like this 1 -0.1 1 0 1 0.1 2 0 2 0.2 2 -0.2 How... (10 Replies)
Discussion started by: bjoern456
10 Replies

10. Shell Programming and Scripting

awk to look up values in File 2 from File 1, & printingNth field of File1 based value of File2 $2

I have two files which are the output of a multiple choice vocab test (60 separate questions) from 104 people (there are some missing responses) and the question list. I have the item list in one file (File1) Item,Stimulus,Choice1,Choice2,Choice3,Choice4,Correct... (5 Replies)
Discussion started by: samonl
5 Replies
FS_GETSERVERPREFS(1)					       AFS Command Reference					      FS_GETSERVERPREFS(1)

NAME
fs_getserverprefs - Displays preference ranks for file servers or VL servers SYNOPSIS
fs getserverprefs [-file <output to named file>] [-numeric] [-vlservers] [-help] fs gets [-f <output to named file>] [-n] [-v] [-h] fs gp [-f <output to named file>] [-n] [-v] [-h] DESCRIPTION
The fs getserverprefs command displays preference ranks for file server machine interfaces (file server machines run the fs process) or, if the -vlserver flag is provided, for Volume Location (VL) Server machines (which run the vlserver process). For file server machines, the Cache Manager tracks up to 15 interfaces per machine and assigns a separate rank to each interface. The ranks indicate the order in which the local Cache Manager attempts to contact the interfaces of machines that are housing a volume when it needs to fetch data from the volume. For VL Server machines, the ranks indicate the order in which the Cache Manager attempts to contact a cell's VL Servers when requesting VLDB information. For both types of rank, lower integer values are more preferred. The Cache Manager stores ranks in kernel memory. Once set, a rank persists until the machine reboots, or until the fs setserverprefs command is used to change it. fs_setserverprefs(1) explains how the Cache Manager sets default ranks, and how to use that command to change the default values. Default VL Server ranks range from 10,000 to 10,126. The Cache Manager assigns ranks to every machine listed in its copy of the /etc/openafs/CellServDB file or found via DNS AFSDB or SRV records for the cell when it initializes. When the Cache Manager needs to fetch VLDB information from a cell, it compares the ranks for the VL Server machines belonging to that cell, and attempts to contact the VL Server with the lowest integer rank. If the Cache Manager cannot reach the VL Server (because of server process, machine or network outage), it tries to contact the VL Server with the next lowest integer rank, and so on. If all of a cell's VL Server machines are unavailable, the Cache Manager cannot fetch data from the cell. Default file server ranks range from 5,000 to 40,000, excluding the range used for VL Servers (10,000 to 10,126); the maximum possible rank is 65,534. When the Cache Manager needs to fetch data from a volume, it compares the ranks for the interfaces of machines that house the volume, and attempts to contact the interface that has the lowest integer rank. If it cannot reach the fileserver process via that interface (because of server process, machine or network outage), it tries to contact the interface with the next lowest integer rank, and so on. If it cannot reach any of the interfaces for machines that house the volume, it cannot fetch data from the volume. For both file server machines and VL Server machines, it is possible for a machine or interface in a foreign cell to have the same rank as a machine or interface in the local cell. This does not present a problem, because the Cache Manager only ever compares ranks for machines belonging to one cell at a time. OPTIONS
-file <output file> Specifies the full pathname of a file to which to write the preference ranks. If the specified file already exists, the command overwrites its contents. If the pathname is invalid, the command fails. If this argument is not provided, the preference ranks appear on the standard output stream. -numeric Displays the IP addresses of file server machine interfaces or VL Server machines, rather than their hostnames. If this argument is not provided, the fs command interpreter has the IP addresses translated to hostnames such as "fs1.abc.com". -vlservers Displays preference ranks for VL Server machines rather than file server machine interfaces. -help Prints the online help for this command. All other valid options are ignored. OUTPUT
The output consists of a separate line for each file server machine interface or VL Server machine, pairing the machine's hostname or IP address with its rank. The Cache Manager stores IP addresses in its kernel list of ranks, but the command by default identifies interfaces by hostname, by calling a translation routine that refers to either the cell's name service (such as the Domain Name Server) or the local host table. If an IP address appears in the output, it is because the translation attempt failed. To bypass the translation step and display IP addresses rather than hostnames, include the -numeric flag. This can significantly speed the production of output. By default, the command writes to the standard output stream. Use the -file argument to write the output to a file instead. EXAMPLES
The following example displays the local Cache Manager's preference ranks for file server machines. The local machine belongs to the AFS cell named abc.com, and in this example the ranks of file server machines in its local cell are lower than the ranks of file server machines from the foreign cell, "def.com". It is not possible to translate the IP addresses of two machines on the 138.255 network. % fs getserverprefs fs2.abc.com 20007 fs3.abc.com 30002 fs1.abc.com 20011 fs4.abc.com 30010 server1.def.com 40002 138.255.33.34 40000 server6.def.com 40012 138.255.33.37 40005 The following example shows hows the output displays IP addresses when the -numeric flag is included, and illustrates how network proximity determines default ranks (as described on the fs setserverprefs reference page). The local machine has IP address 192.12.107.210, and the two file server machines on its subnetwork have ranks of 20,007 and 20,011. The two file server machines on a different subnetwork of the local machine's network have higher ranks, 30,002 and 30,010, whereas the ranks of the remaining machines range from 40,000 to 40,012 because they are in a completely different network. % fs getserverprefs -numeric 192.12.107.214 20007 192.12.105.99 30002 192.12.107.212 20011 192.12.105.100 30010 138.255.33.41 40002 138.255.33.34 40000 138.255.33.36 40012 138.255.33.37 40005 The example shows how the -vlservers flag displays preference ranks for VL Server machines: % fs getserverprefs -vlservers fs2.abc.com 10052 fs3.abc.com 10113 fs1.abc.com 10005 PRIVILEGE REQUIRED
None SEE ALSO
fs_setserverprefs(1) COPYRIGHT
IBM Corporation 2000. <http://www.ibm.com/> All Rights Reserved. This documentation is covered by the IBM Public License Version 1.0. It was converted from HTML to POD by software written by Chas Williams and Russ Allbery, based on work by Alf Wachsmann and Elizabeth Cassell. OpenAFS 2012-03-26 FS_GETSERVERPREFS(1)
All times are GMT -4. The time now is 01:59 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy