Sponsored Content
Full Discussion: Qn on awk greping values
Top Forums UNIX for Beginners Questions & Answers Qn on awk greping values Post 302999967 by MadeInGermany on Friday 30th of June 2017 05:56:27 PM
Old 06-30-2017
Your example is a bit odd.
And comparing all the columns with one number is a bit odd, too.
The following demonstrates how the header is stored in a buffer header and how control variables inheader and doheader control the collecting of the buffer and its printing, respectively.
The decision if its the header is done by the (NF<12) condition.
Code:
awk '(NF<12) {if (inheader) {header=(header RS $0)} else {header=$0; inheader=doheader=1} next} {inheader=0; for (i=2; i<=NF; i++) if ($i+0>=50) {if (doheader) {print header; doheader=0} print; break}}' infile

Or, as a multi-liner
Code:
awk '
(NF<12) {
  if (inheader) {
    header=(header RS $0)
  } else {
    header=$0
    inheader=doheader=1
  }
  next
}
{
  inheader=0
  for (i=2; i<=NF; i++)
    if ($i+0>=50) {
      if (doheader) {
        print header
        doheader=0
      }
      print
      break
    }
}' infile

This User Gave Thanks to MadeInGermany For This Post:
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

problem in greping the string from file using awk

I am using awk command for greping an value from the file the file contains .. file ---------------------------- content----------- -------- String main = "81507066666"; ------------------------------ i am greping the above value using awk command NumberToReplace=`cat "file" | grep... (1 Reply)
Discussion started by: vastare
1 Replies

2. Shell Programming and Scripting

How to pick values from column based on key values by usin AWK

Dear Guyz:) I have 2 different input files like this. I would like to pick the values or letters from the inputfile2 based on inputfile1 keys (A,F,N,X,Z). I have done similar task by using awk but in that case the inputfiles are similar like in inputfile2 (all keys in 1st column and values in... (16 Replies)
Discussion started by: repinementer
16 Replies

3. Shell Programming and Scripting

AWK: read values from file1; search for values in file2

I have read another post about this issue and am wondering how to adapt it to my own, much simpler, issue. I have a file of user IDs like so: 333333 321321 546465 ...etc I need to take each number and use it to print records wherein the 5th field matches the user ID pulled from the... (2 Replies)
Discussion started by: Bubnoff
2 Replies

4. Shell Programming and Scripting

Greping array values in Bash like Perl

Hi, Is there an easy way to simulate following Perl code in Bash. if ( grep {$my_value eq $_} @ARGV ){ print "Do Something\n"; } else { die "Invalid value"; } (0 Replies)
Discussion started by: paragkalra
0 Replies

5. Shell Programming and Scripting

Greping the column with a value greater than 50 with awk

Hi All, I am running a command from a remote server using ssh to different servers. I will get a output like below with 4 columns. I want to grab line which is having a coulmn which grate than or equal to 50. How can I do it with Awk or sed ??. I add a space to first row with sed 's/::/:: /g' to... (4 Replies)
Discussion started by: raghin
4 Replies

6. Shell Programming and Scripting

Greping values from a text file

Hi All, I have 100's of files in the following format. I need to grep or parse out some values from each of the files {  “tree”: “((A:0.2{0},B:0.09{1}):0.7{2},C:0.5{3}){​4};”,  “placements”:  , ], “n”: },   {“p”: ], “n”: } ],  “metadata”:  {“invocation”:   “pplacer -c... (1 Reply)
Discussion started by: Lucky Ali
1 Replies

7. Shell Programming and Scripting

How to find the X highest values in a list depending on the values of another list with bash/awk?

Hi everyone, This is an exemple of inpout.txt file (a "," delimited text file which can be open as csv file): ID, Code, Value, Store SP|01, AABBCDE, 15, 3 SP|01, AABBCDE, 14, 2 SP|01, AABBCDF, 13, 2 SP|01, AABBCDE, 16, 3 SP|02, AABBCED, 15, 2 SP|01, AABBCDF, 12, 3 SP|01, AABBCDD,... (1 Reply)
Discussion started by: jeremy589
1 Replies

8. Shell Programming and Scripting

awk file to read values from Db2 table replacing hard coded values

Hi, I want to replace a chain of if-else statement in an old AWK file with values from Db2 table or CSV file. The part of code is below... if (start_new_rec=="true"){ exclude_user="false"; user=toupper($6); match(user, "XXXXX."); if (RSTART ==2 ) { ... (9 Replies)
Discussion started by: asandy1234
9 Replies

9. Shell Programming and Scripting

awk and greping between lines

i want to grab lines from a file that are between two patterns (including the lines that contain the pattern). here's what im currently doing: data.txt aaa bbb cccc ddd eee ffff ddd code: awk '/bbb/,/fff/ && $0 !~ /ddd/' cdsnmp.sh I want to grab lines between and including bbb... (5 Replies)
Discussion started by: SkySmart
5 Replies
inet6_rth_space(3N)													       inet6_rth_space(3N)

NAME
inet6_rth_add(), inet6_rth_getaddr(), inet6_rth_init(), inet6_rth_reverse(), inet6_rth_segments(), inet6_rth_space() - IPv6 Routing header options manipulation functions. SYNOPSIS
DESCRIPTION
These functions can be used by an application to build and examine an IPv6 Routing header. The Routing header can be used by an IPv6 source to list one or more intermediate nodes to be visited on the way to a packet's destination. These three functions build a Routing header: returns the number of bytes required for a Routing header. initializes the buffer data for a Routing header. adds one IPv6 address to the Routing header. Three functions deal with a returned Routing header: reverses a Routing header. returns the number of segments in a Routing header. fetches one address from a Routing header. These functions are described below: This function returns the number of bytes required to hold a routing header of the specified type containing the specified number of segments (addresses). For an IPv6 Type 0 Routing header, the number of segments must be between 0 and 127, inclusive. The return value is just the space for the Routing header. When the application uses ancillary data, it must pass the returned length to to determine how much memory is needed for the ancillary data object (includ- ing the structure). If the return value is 0, then either the type of the Routing header is not supported by this implementation or the number of segments is invalid for this type of Routing header. This function returns the size but does not allocate the space required for the ancillary data. Note: If type is 2 (Routing Header Type 2), segments must be 1 (RFC 4584). This function initializes the buffer pointed to by bp to contain a Routing header of the specified type. bp_len is only used to verify if the buffer is large enough. The caller must allocate the buffer, and its size can be determined by calling Upon success, the return value is the pointer to the buffer (bp), and the pointer is then used as the first argument to the function. Upon an error, the return value is NULL. Note: If type is 2 (Routing Header Type 2), segments must be 1 (RFC 4584). This function adds the IPv6 address pointed to by addr to the end of the Routing header being constructed. If successful, the member of the Routing header is updated to account for the new address in the Routing header and the return value of the function is 0. Upon an error the return value of the function is -1. Note: If the Routing header is type 2, this function can only be called once. This function takes a Routing header extension header pointed to by the first argument in and writes a new Routing header. The new Routing header sends datagrams along the reverse of that route. The function reverses the order of the addresses and sets the member in the new routing header to the number of segments. Both arguments are allowed to point to the same buffer (that is, the reversal can occur in place). The return value of the function is 0 on success, or -1 upon an error. Note: If Routing header is type 2, this function returns -1 (RFC 4584). This function returns the number of segments (addresses) contained in the Routing header described by bp which can be 0 or greater. The return value of the function is -1 upon an error. This function returns a pointer to the IPv6 address specified by index (which must be a value between 0 and one less than the value returned by in the Routing header described by bp. An application should first call to obtain the number of segments in the Routing header. Upon an error, the return value of the function is NULL. Note: If Routing header is type 2, this function returns a pointer to the IPv6 home address specified by the ip6r2_homeaddr field in which is pointed by bp. The index must be zero. Notes To use these functions, the application must be compiled with: To receive a Routing header, the application must enable the socket option: To send a Routing header, the application specifies it either as ancillary data in a call to or using (see send(2) and getsockopt(2), respectively). EXAMPLES
gives a comprehensive example in Appendix B. SEE ALSO
send(2), getsockopt(2), IPv6(7P), xopen_networking(7). inet6_rth_space(3N)
All times are GMT -4. The time now is 10:04 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy