Sponsored Content
Top Forums Shell Programming and Scripting Print row if value in column 1 is the first occurence Post 302175998 by Shivdatta on Monday 17th of March 2008 04:58:43 AM
Old 03-17-2008
$cat test
0001 k= 40
0001 k= 2
0002 k= 1
0003 k= 1
0004 k= 77
0004 k= 1
0005 k= 88
0005 k= 6



for i in `cat test|cut -d" " -f1`
do
grep "$i" test | head -1 >> out.txt
done
sort -u out.txt

0001 k= 40
0002 k= 1
0003 k= 1
0004 k= 77
0005 k= 88
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to print column based on row number

Hi, I want to print column value based on row number say multiple of 8. Input file: line 1 67 34 line 2 45 57 . . . . . . line 8 12 46 . . . . . . line 16 24 90 . . . . . . line 24 49 67 Output 46 90 67 (2 Replies)
Discussion started by: Surabhi_so_mh
2 Replies

2. Shell Programming and Scripting

AWK Script - Print a column - within a Row Range

Hi, Please read the whole thread. I have been working on this script below. It works fine, feel free to copy and test with the INPUT File below as well. example: PACKET DATA PROTOCOL CONTEXT DATA APNID PDPADD EQOSID VPAA PDPCH PDPTY PDPID 10 ... (6 Replies)
Discussion started by: panapty
6 Replies

3. Shell Programming and Scripting

Print the row element till the next row element appear in a column

Hi all I have file with columns F3 pathway CPS F2 H2 H4 H5 H6 no pathway CMP H7 H8 H9 H10 My expected output is F3 pathway CPS F2 pathway CPS (10 Replies)
Discussion started by: Priyanka Chopra
10 Replies

4. Shell Programming and Scripting

Print unique names in each row of a specific column using awk

Is it possible to remove redundant names in the 4th column? input cqWE 100 200 singapore;singapore AZO 300 400 brazil;america;germany;ireland;germany .... .... output cqWE 100 200 singapore AZO 300 400 brazil;america;germany;ireland (4 Replies)
Discussion started by: quincyjones
4 Replies

5. UNIX for Dummies Questions & Answers

awk to print first row with forth column and last row with fifth column in each file

file with this content awk 'NR==1 {print $4} && NR==2 {print $5}' file The error is shown with syntax error; what can be done (4 Replies)
Discussion started by: cdfd123
4 Replies

6. Shell Programming and Scripting

Print every 5 4th column values as separate row with different first column

Hi, I have the following file, chr1 100 200 20 chr1 201 300 22 chr1 220 345 23 chr1 230 456 33.5 chr1 243 567 90 chr1 345 600 20 chr1 430 619 21.78 chr1 870 910 112.3 chr1 914 920 12 chr1 930 999 13 My output would be peak1 20 22 23 33.5 90 peak2 20 21.78 112.3 12 13 Here the... (3 Replies)
Discussion started by: jacobs.smith
3 Replies

7. Shell Programming and Scripting

Print row on 4th column to all row

Dear All, I have input : SEG901 5173 9005 5740 SEG902 5227 5284 SEG903 5284 5346 SEG904 5346 9010 SEG905 5400 5456 SEG906 5456 5511 SEG907 5511 9011 SEG908 5572 9015 SEG909 5622 9020 SEG910 5678 5739 SEG911 5739 5796 SEG912 5796 9025 ... (3 Replies)
Discussion started by: attila
3 Replies

8. Shell Programming and Scripting

Print first row of column a, last row of column b if column a has the same value

I have a table with this structure: cola colb colc 1 19 lemon 20 31 lemon 32 100 lemon 159 205 cherries 210 500 cherries and need to parse it into this format: cola colb colc 1 100 lemon 159 500 cherries So I need the first row of cola and the last row of colb if colc has the... (3 Replies)
Discussion started by: coppuca
3 Replies

9. Shell Programming and Scripting

Print every alternate column in row in a text file

Hi, I have a comma separated file. I would like to print every alternate columns into a new row. Example input file: Name : John, Age : 30, DOB : 30-Oct-2018 Example output: Name,Age,DOB John,30,30-Oct-2018 (3 Replies)
Discussion started by: Lini
3 Replies

10. UNIX for Beginners Questions & Answers

Print a row with the max number in a column

Hello, I have this table: chr1_16857_17742 - chr1 17369 17436 "ENST00000619216.1"; "MIR6859-1"; - 67 chr1_16857_17742 - chr1 14404 29570 "ENST00000488147.1"; "WASH7P"; - 885 chr1_16857_18061 - chr1 ... (5 Replies)
Discussion started by: coppuca
5 Replies
CIDR(3pm)						User Contributed Perl Documentation						 CIDR(3pm)

NAME
Net::CIDR - Manipulate IPv4/IPv6 netblocks in CIDR notation SYNOPSIS
use Net::CIDR; use Net::CIDR ':all'; print join(" ", Net::CIDR::range2cidr("192.68.0.0-192.68.255.255", "10.0.0.0-10.3.255.255")) . " "; # # Output from above: # # 192.68.0.0/16 # 10.0.0.0/14 print join(" ", Net::CIDR::range2cidr( "dead:beef::-dead:beef:ffff:ffff:ffff:ffff:ffff:ffff")) . " "; # # Output from above: # # dead:beef::/32 print join(" ", Net::CIDR::range2cidr("192.68.1.0-192.68.2.255")) . " "; # # Output from above: # # 192.68.1.0/24 # 192.68.2.0/24 print join(" ", Net::CIDR::cidr2range("192.68.0.0/16")) . " "; # # Output from above: # # 192.68.0.0-192.68.255.255 print join(" ", Net::CIDR::cidr2range("dead::beef::/46")) . " "; # # Output from above: # # dead:beef::-dead:beef:3:ffff:ffff:ffff:ffff:ffff @list=("192.68.0.0/24"); @list=Net::CIDR::cidradd("192.68.1.0-192.68.1.255", @list); print join(" ", @list) . " "; # # Output from above: # # 192.68.0.0/23 print join(" ", Net::CIDR::cidr2octets("192.68.0.0/22")) . " "; # # Output from above: # # 192.68.0 # 192.68.1 # 192.68.2 # 192.68.3 print join(" ", Net::CIDR::cidr2octets("dead::beef::/46")) . " "; # # Output from above: # # dead:beef:0000 # dead:beef:0001 # dead:beef:0002 # dead:beef:0003 @list=("192.68.0.0/24"); print Net::CIDR::cidrlookup("192.68.0.12", @list); # # Output from above: # # 1 @list = Net::CIDR::addr2cidr("192.68.0.31"); print join(" ", @list); # # Output from above: # # 192.68.0.31/32 # 192.68.0.30/31 # 192.68.0.28/30 # 192.68.0.24/29 # 192.68.0.16/28 # 192.68.0.0/27 # 192.68.0.0/26 # 192.68.0.0/25 # 192.68.0.0/24 # 192.68.0.0/23 # [and so on] print Net::CIDR::addrandmask2cidr("195.149.50.61", "255.255.255.248")." "; # # Output from above: # # 195.149.50.56/29 DESCRIPTION
The Net::CIDR package contains functions that manipulate lists of IP netblocks expressed in CIDR notation. The Net::CIDR functions handle both IPv4 and IPv6 addresses. @cidr_list=Net::CIDR::range2cidr(@range_list); Each element in the @range_list is a string "start-finish", where "start" is the first IP address and "finish" is the last IP address. range2cidr() converts each range into an equivalent CIDR netblock. It returns a list of netblocks except in the case where it is given only one parameter and is called in scalar context. For example: @a=Net::CIDR::range2cidr("192.68.0.0-192.68.255.255"); The result is a one-element array, with $a[0] being "192.68.0.0/16". range2cidr() processes each "start-finish" element in @range_list separately. But if invoked like so: $a=Net::CIDR::range2cidr("192.68.0.0-192.68.255.255"); The result is a scalar "192.68.0.0/16". Where each element cannot be expressed as a single CIDR netblock range2cidr() will generate as many CIDR netblocks as are necessary to cover the full range of IP addresses. Example: @a=Net::CIDR::range2cidr("192.68.1.0-192.68.2.255"); The result is a two element array: ("192.68.1.0/24","192.68.2.0/24"); @a=Net::CIDR::range2cidr( "d08c:43::-d08c:43:ffff:ffff:ffff:ffff:ffff:ffff"); The result is an one element array: ("d08c:43::/32") that reflects this IPv6 netblock in CIDR notation. range2cidr() does not merge adjacent or overlapping netblocks in @range_list. @range_list=Net::CIDR::cidr2range(@cidr_list); The cidr2range() functions converts a netblock list in CIDR notation to a list of "start-finish" IP address ranges: @a=Net::CIDR::cidr2range("10.0.0.0/14", "192.68.0.0/24"); The result is a two-element array: ("10.0.0.0-10.3.255.255", "192.68.0.0-192.68.0.255"). @a=Net::CIDR::cidr2range("d08c:43::/32"); The result is a one-element array: ("d08c:43::-d08c:43:ffff:ffff:ffff:ffff:ffff:ffff"). cidr2range() does not merge adjacent or overlapping netblocks in @cidr_list. @netblock_list = Net::CIDR::addr2cidr($address); The addr2cidr function takes an IP address and returns a list of all the CIDR netblocks it might belong to: @a=Net::CIDR::addr2cidr('192.68.0.31'); The result is a thirtythree-element array: ('192.68.0.31/32', '192.68.0.30/31', '192.68.0.28/30', '192.68.0.24/29', [and so on]) consisting of all the possible subnets containing this address from 0.0.0.0/0 to address/32. Any addresses supplied to addr2cidr after the first will be ignored. It works similarly for IPv6 addresses, returning a list of one hundred and twenty nine elements. $cidr=Net::CIDR::addrandmask2cidr($address, $netmask); The addrandmask2cidr function takes an IP address and a netmask, and returns the CIDR range whose size fits the netmask and which contains the address. It is an error to supply one parameter in IPv4-ish format and the other in IPv6-ish format, and it is an error to supply a netmask which does not consist solely of 1 bits followed by 0 bits. For example, '255.255.248.192' is an invalid netmask, as is '255.255.255.32' because both contain 0 bits in between 1 bits. Technically speaking both of those *are* valid netmasks, but a) you'd have to be insane to use them, and b) there's no corresponding CIDR range. @octet_list=Net::CIDR::cidr2octets(@cidr_list); cidr2octets() takes @cidr_list and returns a list of leading octets representing those netblocks. Example: @octet_list=Net::CIDR::cidr2octets("10.0.0.0/14", "192.68.0.0/24"); The result is the following five-element array: ("10.0", "10.1", "10.2", "10.3", "192.68.0"). For IPv6 addresses, the hexadecimal words in the resulting list are zero-padded: @octet_list=Net::CIDR::cidr2octets("::dead:beef:0:0/110"); The result is a four-element array: ("0000:0000:0000:0000:dead:beef:0000", "0000:0000:0000:0000:dead:beef:0001", "0000:0000:0000:0000:dead:beef:0002", "0000:0000:0000:0000:dead:beef:0003"). Prefixes of IPv6 CIDR blocks should be even multiples of 16 bits, otherwise they can potentially expand out to a 32,768-element array, each! @cidr_list=Net::CIDR::cidradd($block, @cidr_list); The cidradd() functions allows a CIDR list to be built one CIDR netblock at a time, merging adjacent and overlapping ranges. $block is a single netblock, expressed as either "start-finish", or "address/prefix". Example: @cidr_list=Net::CIDR::range2cidr("192.68.0.0-192.68.0.255"); @cidr_list=Net::CIDR::cidradd("10.0.0.0/8", @cidr_list); @cidr_list=Net::CIDR::cidradd("192.68.1.0-192.68.1.255", @cidr_list); The result is a two-element array: ("10.0.0.0/8", "192.68.0.0/23"). IPv6 addresses are handled in an analogous fashion. $found=Net::CIDR::cidrlookup($ip, @cidr_list); Search for $ip in @cidr_list. $ip can be a single IP address, or a netblock in CIDR or start-finish notation. lookup() returns 1 if $ip overlaps any netblock in @cidr_list, 0 if not. $ip=Net::CIDR::cidrvalidate($ip); Validate whether $ip is a valid IPv4 or IPv6 address, or a CIDR. Returns its argument or undef. Spaces are removed, and IPv6 hexadecimal address are converted to lowercase. If $ip contains a "/", it must be a valid CIDR, otherwise it must be a valid IPv4 or an IPv6 address. A technically invalid CIDR, such as "192.168.0.1/24" fails validation, returning undef. BUGS
Garbage in, garbage out. Always use cidrvalidate() before doing anything with untrusted input. Otherwise, "slightly" invalid input will work (extraneous whitespace is generally OK), but the functions will croak if you're totally off the wall. AUTHOR
Sam Varshavchik <sam@email-scan.com> With some contributions from David Cantrell <david@cantrell.org.uk> perl v5.14.2 2012-05-01 CIDR(3pm)
All times are GMT -4. The time now is 03:22 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy