Sponsored Content
Top Forums UNIX for Advanced & Expert Users Print line based on highest value of col (B) and repetion of values in col (A) Post 302541327 by agama on Saturday 23rd of July 2011 09:08:41 PM
Old 07-23-2011
Assuming that the input file is sorted, this should work:

Code:
awk '

    {
        if( last && last != $1 )     # we have a different first token
        {
            print saved;             # show the record with largest 3rd token
            exit( 0 );
        }

        last = $1;
        split( $3, a, "=" );
        if( a[2] > max )          # token 3 is greater than max seen
        {
            saved = $0;           # save this record
            max = a[2];
        }
    }
' input-file

This User Gave Thanks to agama For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Awk to print distinct col values

Hi Guys... I am newbie to awk and would like a solution to probably one of the simple practical questions. I have a test file that goes as: 1,2,3,4,5,6 7,2,3,8,7,6 9,3,5,6,7,3 8,3,1,1,1,1 4,4,2,2,2,2 I would like to know how AWK can get me the distinct values say for eg: on col2... (22 Replies)
Discussion started by: anduzzi
22 Replies

2. Ubuntu

Match col 1 of File 1 with col 1 File 2 and create a 3rd file

Hello, I have a 1.6 GB file that I would like to modify by matching some ids in col1 with the ids in col 1 of file2.txt and save the results into a 3rd file. For example: File 1 has 1411 rows, I ignore how many columns it has (thousands) File 2 has 311 rows, 1 column Would like to... (7 Replies)
Discussion started by: sogi
7 Replies

3. Shell Programming and Scripting

Retrieving data from 65th col (of each line) ?

Hello Friends, I am in situation where I have to note down few SQL queries from specific hexdump format. Here is an example (the query text starts at 65th character on each line) ---------------------- 0x000007FEB0E701C0 : 7365 6C65 6374 2063 7573 746E 6F2C 2020 select custno, ... (9 Replies)
Discussion started by: Sunusernewbie
9 Replies

4. Shell Programming and Scripting

Printing from col x to end of line, except last col

Hello, I have some tab delimited data and I need to move the last col. I could hard code it, awk '{ print $1,$NF,$2,$3,$4,etc }' infile > outfile but it would be nice to know the syntax to print a range cols. I know in cut you can do, cut -f 1,4-8,11- to print fields 1,... (8 Replies)
Discussion started by: LMHmedchem
8 Replies

5. Shell Programming and Scripting

Run a program-print parameters to output file-replace op file contents with max 4th col

Hi Friends, This is the only solution to my task. So, any help is highly appreciated. I have a file cat input1.bed chr1 100 200 abc chr1 120 300 def chr1 145 226 ghi chr2 567 600 unix Now, I have another file by name input2.bed (This file is a binary file not readable by the... (7 Replies)
Discussion started by: jacobs.smith
7 Replies

6. Shell Programming and Scripting

Modifying col values based on another col

Hi, Please help with this. I have several excel files (with and .xlsx format) with 10-15 columns each. They all have the same type of data but the columns are not ordered in the same way. Here is a 3 column example. What I want to do add the alphabet from column 2 to column 3, provided... (9 Replies)
Discussion started by: newbie83
9 Replies

7. Shell Programming and Scripting

Print lines that contain a value in a specific column shared by more than 1 entity in another col

I want to expand on a question that I just asked here: I want to extract only those values in Column 2 that are shared by at least 2 unique values in Column 2. Using the same input (in this case 3- tab-separated columns): waterline-n below-sheath-v 14.8097 dock-n below-sheath-v ... (2 Replies)
Discussion started by: owwow14
2 Replies

8. Shell Programming and Scripting

Print lines in which value in specified Col is NOT unique

Hi everyone, I have the following file, which is a 3 column tab-delineated. cat big 24 cat small 13 cat red 63 dog big 34 chicken plays 39 fish red 294 I would like to print only those lines, in which the value in Col2 is repeated. Thus, given the above input file, the desired... (7 Replies)
Discussion started by: owwow14
7 Replies

9. Shell Programming and Scripting

How to mark the row based on col value.?

Hi Gurus, I have requirement to identify the records based on one column value. the sample file as below: ID AMT, AMT1 100,10, 2 100,20, 3 200,30, 0 200, 40, 0 300, 20, 2 300, 50, 2 400, 20, 1 400, 60, 0 for each ID, there 2 records, if any one record amt1 is 0, the in 4th col add... (5 Replies)
Discussion started by: ken6503
5 Replies

10. Emergency UNIX and Linux Support

Read values in each col starting 3rd row.Print occurrence value.

Hello Friends, Hope all are doing fine. Here is a tricky issue. my input file is like this 07 10 14 20 21 03 15 27 30 32 01 10 11 19 30 02 06 14 15 17 01 06 20 25 29 Logic: 1. Please print another column as "0-0-0-0-0" for the first and second rows. 2. Read the first column... (4 Replies)
Discussion started by: jacobs.smith
4 Replies
Tcl_SaveResult(3)					      Tcl Library Procedures						 Tcl_SaveResult(3)

__________________________________________________________________________________________________________________________________________________

NAME
Tcl_SaveInterpState, Tcl_RestoreInterpState, Tcl_DiscardInterpState, Tcl_SaveResult, Tcl_RestoreResult, Tcl_DiscardResult - save and restore an interpreter's state SYNOPSIS
#include <tcl.h> Tcl_InterpState Tcl_SaveInterpState(interp, status) int Tcl_RestoreInterpState(interp, state) Tcl_DiscardInterpState(state) Tcl_SaveResult(interp, savedPtr) Tcl_RestoreResult(interp, savedPtr) Tcl_DiscardResult(savedPtr) ARGUMENTS
Tcl_Interp *interp (in) Interpreter for which state should be saved. int status (in) Return code value to save as part of interpreter state. Tcl_InterpState state (in) Saved state token to be restored or discarded. Tcl_SavedResult *savedPtr (in) Pointer to location where interpreter result should be saved or restored. _________________________________________________________________ DESCRIPTION
These routines allows a C procedure to take a snapshot of the current state of an interpreter so that it can be restored after a call to | Tcl_Eval or some other routine that modifies the interpreter state. There are two triplets of routines meant to work together. | The first triplet stores the snapshot of interpreter state in an opaque token returned by Tcl_SaveInterpState. That token value may then | be passed back to one of Tcl_RestoreInterpState or Tcl_DiscardInterpState, depending on whether the interp state is to be restored. So | long as one of the latter two routines is called, Tcl will take care of memory management. | The second triplet stores the snapshot of only the interpreter result (not its complete state) in memory allocated by the caller. These | routines are passed a pointer to a Tcl_SavedResult structure that is used to store enough information to restore the interpreter result. | This structure can be allocated on the stack of the calling procedure. These routines do not save the state of any error information in | the interpreter (e.g. the -errorcode or -errorinfo return options, when an error is in progress). | Because the routines Tcl_SaveInterpState, Tcl_RestoreInterpState, and Tcl_DiscardInterpState perform a superset of the functions provided | by the other routines, any new code should only make use of the more powerful routines. The older, weaker routines Tcl_SaveResult, | Tcl_RestoreResult, and Tcl_DiscardResult continue to exist only for the sake of existing programs that may already be using them. | Tcl_SaveInterpState takes a snapshot of those portions of interpreter state that make up the full result of script evaluation. This | include the interpreter result, the return code (passed in as the status argument, and any return options, including -errorinfo and -error- | code when an error is in progress. This snapshot is returned as an opaque token of type Tcl_InterpState. The call to Tcl_SaveInterpState | does not itself change the state of the interpreter. Unlike Tcl_SaveResult, it does not reset the interpreter. | Tcl_RestoreInterpState accepts a Tcl_InterpState token previously returned by Tcl_SaveInterpState and restores the state of the interp to | the state held in that snapshot. The return value of Tcl_RestoreInterpState is the status value originally passed to Tcl_SaveInterpState | when the snapshot token was created. | Tcl_DiscardInterpState is called to release a Tcl_InterpState token previously returned by Tcl_SaveInterpState when that snapshot is not to | be restored to an interp. | The Tcl_InterpState token returned by Tcl_SaveInterpState must eventually be passed to either Tcl_RestoreInterpState or Tcl_DiscardInterp- | State to avoid a memory leak. Once the Tcl_InterpState token is passed to one of them, the token is no longer valid and should not be used | anymore. Tcl_SaveResult moves the string and object results of interp into the location specified by statePtr. Tcl_SaveResult clears the result for interp and leaves the result in its normal empty initialized state. Tcl_RestoreResult moves the string and object results from statePtr back into interp. Any result or error that was already in the inter- preter will be cleared. The statePtr is left in an uninitialized state and cannot be used until another call to Tcl_SaveResult. Tcl_DiscardResult releases the saved interpreter state stored at statePtr. The state structure is left in an uninitialized state and can- not be used until another call to Tcl_SaveResult. Once Tcl_SaveResult is called to save the interpreter result, either Tcl_RestoreResult or Tcl_DiscardResult must be called to properly clean up the memory associated with the saved state. KEYWORDS
result, state, interp Tcl 8.1 Tcl_SaveResult(3)
All times are GMT -4. The time now is 12:17 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy