Sponsored Content
Top Forums Shell Programming and Scripting Filter and sort the file using awk Post 303007349 by Scott on Wednesday 15th of November 2017 11:16:40 AM
Old 11-15-2017
But, the output you get is nothing like the output you expected. You can't arbitrarily join four lines together, out of context, and get the output you expect!

But if you're happy... Smilie

Another one:
Code:
$ grep --no-group-separator -B1 -A2 "^[[:space:]].*R1$" file | paste - - - - | awk '$1=$1'
Device Symmetrix Name : 000AB RDF Type : R1 Remote Device Symmetrix Name : 000A1 Remote Symmetrix ID : frame1
Device Symmetrix Name : 000AC RDF Type : R1 Remote Device Symmetrix Name : 000A2 Remote Symmetrix ID : frame1
Device Symmetrix Name : 000AD RDF Type : R1 Remote Device Symmetrix Name : 000A3 Remote Symmetrix ID : frame1

This is around three+ times quicker than the pure awk solutions - grep is more efficient at doing the filtering, before the results get to paste or awk. For example, taking your input x 1,000,000:

This:
Code:
real	0m5.986s
user	0m4.988s
sys	0m0.818s

Respective awk solutions:
Code:
(Ravinder)
real	0m17.374s
user	0m16.626s
sys	0m0.547s

(RudiC)
real	0m28.287s
user	0m27.426s
sys	0m0.597s

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

filter parts of a big file using awk or sed script

I need an assistance in file generation using awk, sed or anything... I have a big file that i need to filter desired parts only. The objective is to select (and print) the report # having the string "apple" on 2 consecutive lines in every report. Please note that the "apple" line has a HEX... (1 Reply)
Discussion started by: apalex
1 Replies

2. Shell Programming and Scripting

Filter records in a file using AWK

I want to filter records in one of my file using AWK command (or anyother command). I am using the below code awk -F@ '$1=="0003"&&"$2==20100402" print {$0}' $INPUT > $OUTPUT I want to pass the 0003 and 20100402 values through a variable. How can I do this? Any help is much... (1 Reply)
Discussion started by: gpaulose
1 Replies

3. Shell Programming and Scripting

AWK filter from file and print

Dear all, I am using awk to filter some data like this:- awk 'NR==FNR{a;next}($1 in a)' FS=":" filter.dat data.dat >! out.dat where the filter and input data look like this:- filter.dat... n_o00j_1900_40_007195350_0:n_o00j_1940_40_007308526... (3 Replies)
Discussion started by: atb299
3 Replies

4. Shell Programming and Scripting

awk-filter record by another file

I have file1 3049 3138 4672 22631 45324 112382 121240 125470 130289 186128 193996 194002 202776 228002 253221 273523 284601 284605 641858 (8 Replies)
Discussion started by: biomed
8 Replies

5. Shell Programming and Scripting

Help with awk, using a file to filter another one

I have a main file: ... 17,466971 0,095185 17,562156 id 676 17,466971 0,096694 17,563665 id 677 17,466971 0,09816 17,565131 id 678 17,466971 0,099625 17,566596 id 679 17,466971 0,101091 17,568062 id 680 17,466971 0,016175 17,483146 id... (4 Replies)
Discussion started by: boblix
4 Replies

6. Shell Programming and Scripting

awk filter by columns of file csv

Hi, I would like extract some lines from file csv using awk , below the example: I have the file test.csv with in content below. FLUSSO;COD;DATA_LAV;ESITO ULL;78;17/09/2013;OL ULL;45;05/09/2013;Apertura NP;45;13/09/2013;Riallineamento ULLNP;78;17/09/2013;OL NPG;14;12/09/2013;AperturaTK... (6 Replies)
Discussion started by: giankan
6 Replies

7. Shell Programming and Scripting

awk to filter file using range in another file

I have a very large tab-delimited, ~2GB file2 that I am trying to filter using $2 of file1. If $2 of file1 is in the range of $2 and $3 in file1 then the entire line of file2 is outputed. If the range match is not found then that line is skipped. The awk below does run but no output results. ... (3 Replies)
Discussion started by: cmccabe
3 Replies

8. Shell Programming and Scripting

awk to filter file using another working on smaller subset

In the below awk if I use the attached file as the input, I get no results for TCF4. However, if I just copy that line from the attached file and use that as input I get results for TCF4. Basically the gene file is a 1 column list that is used to filter $8 of the attached file. When there is a... (9 Replies)
Discussion started by: cmccabe
9 Replies

9. Shell Programming and Scripting

awk to filter file based on seperate conditions

The below awk will filter a list of 30,000 lines in the tab-delimited file. What I am having trouble with is adding a condition to SVTYPE=CNV that will only print that line if CI= must be >.05 . The other condition to add is if SVTYPE=Fusion, then in order to print that line READ_COUNT must... (3 Replies)
Discussion started by: cmccabe
3 Replies

10. Shell Programming and Scripting

Awk/sed/cut to filter out records from a file based on criteria

I have two files and would need to filter out records based on certain criteria, these column are of variable lengths, but the lengths are uniform throughout all the records of the file. I have shown a sample of three records below. Line 1-9 is the item number "0227546_1" in the case of the first... (15 Replies)
Discussion started by: MIA651
15 Replies
Info::Layer2::Bay(3pm)					User Contributed Perl Documentation				    Info::Layer2::Bay(3pm)

NAME
SNMP::Info::Layer2::Bay - SNMP Interface to old Bay Network BayStack Switches AUTHOR
Max Baker SYNOPSIS
This module is Deprecated. Please use Layer2::BayStack instead. DESCRIPTION
Provides abstraction to the configuration information obtainable from a Bay device through SNMP. For speed or debugging purposes you can call the subclass directly, but not after determining a more specific class using the method above. my $bay = new SNMP::Info::Layer2::Bay(...); Inherited Classes SNMP::Info::Layer2 Required MIBs SYNOPTICS-ROOT-MIB S5-ETH-MULTISEG-TOPOLOGY-MIB Inherited classes MIBs required by "Required MIBs" in SNMP::Info::Layer2 and its superclasses. GLOBALS
These are methods that return scalar value from SNMP $bay->vendor() Returns 'bay' :) $bay->model() Cross references $bay->id() to the SYNOPTICS-MIB and returns the results. 303s and 304s have the same ID, so we have a hack to return depending on which it is. Removes "sreg-" from the model name $baystack->os() Returns 'bay'. $bay->os_ver() Returns the os version extracted from "sysDescr". $bay->os_bin() Returns the firmware version extracted from "sysDescr". $bay->cdp_id() Returns the IP that the device is sending out for its Nmm topology info. ("s5EnMsTopIpAddr") $bay->cdp_run() Returns if the S5-ETH-MULTISEG-TOPOLOGY info is on for this device. ("s5EnMsTopStatus") Globals imported from SNMP::Info::Layer2 See documentation in "GLOBALS" in SNMP::Info::Layer2 for details. TABLE METHODS
These are methods that return tables of information in the form of a reference to a hash. Overrides $bay->interfaces() Returns reference to map of IIDs to physical ports. Currently simply returns the "ifIndex" $bay->i_ignore() Returns reference to hash of IIDs to ignore. Simply calls the SNMP::Info::Layer2::i_ignore() for this. $bay->i_mac() Returns the "ifPhysAddress" table entries. Removes all entries matching '00:00:00:00:00:00' -- Certain older revisions of Bay 303 and 304 firmware report all zeros for each port mac. Pseudo CDP information All entries with port=0 are local and ignored. $bay->c_if() Returns reference to hash. Key: port.1 Value: port (iid) $bay->c_ip() Returns reference to hash. Key: port.1 The value of each hash entry can either be a scalar or an array. A scalar value is most likely a direct neighbor to that port. It is possible that there is a non-bay device in between this device and the remote device. An array value represents a list of seen devices. The only time you will get an array of neighbors, is if there is a non-bay device in between two or more devices. Use the data from the Layer2 Topology Table below to dig deeper. $bay->c_port() Returns reference to hash. Key: IID, Value: Remote port (interfaces) $bay->c_platform() Returns reference to hash. Key: IID, Value: Remote device type $bay->port() Returns reference to hash. Key: port.1 Value: port $bay->platform() Returns reference to hash. Key: port.1 Value: Remote Device Type Layer2 Topology info ("s5EnMsTopNmmTable") $bay->bay_topo_slot() Returns reference to hash. Key: Table entry, Value:slot number ("s5EnMsTopNmmSlot") $bay->bay_topo_port() Returns reference to hash. Key: Table entry, Value:Port Number (interface iid) ("s5EnMsTopNmmPort") $bay->bay_topo_ip() Returns reference to hash. Key: Table entry, Value:Remote IP address of entry ("s5EnMsTopNmmIpAddr") $bay->bay_topo_seg() Returns reference to hash. Key: Table entry, Value:Remote Segment ID ("s5EnMsTopNmmSegId") $bay->bay_topo_mac ("s5EnMsTopNmmMacAddr") Returns reference to hash. Key: Table entry, Value:Remote MAC address $bay->bay_topo_platform Returns reference to hash. Key: Table entry, Value:Remote Device Type ("s5EnMsTopNmmChassisType") $bay->bay_topo_localseg Returns reference to hash. Key: Table entry, Value:Boolean, if bay_topo_seg() is local ("s5EnMsTopNmmLocalSeg") Table Methods imported from SNMP::Info::Layer2 See documentation in "TABLE METHODS" in SNMP::Info::Layer2 for details. perl v5.12.4 2011-09-28 Info::Layer2::Bay(3pm)
All times are GMT -4. The time now is 10:51 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy