Sponsored Content
Top Forums UNIX for Dummies Questions & Answers keeping last record among group of records with common fields (awk) Post 302711537 by beca123456 on Saturday 6th of October 2012 11:18:18 PM
Old 10-07-2012
keeping last record among group of records with common fields (awk)

input:
Code:
ref.1;rack.1;1     #group1
ref.1;rack.1;2     #group1
ref.1;rack.2;1     #group2
ref.2;rack.3;1     #group3
ref.2;rack.3;2     #group3
ref.2;rack.3;3     #group3

Among records from same group (i.e. with same 1st and 2nd field - separated by ";"), I would need to keep the last record (or the record with the highest number in the last field, which is the same here).

in order to get:
Code:
ref.1;rack.1;2
ref.1;rack.2;1
ref.2;rack.3;3

I think I managed to isolate records in groups by doing
Code:
BEGIN{FS=OFS=";"}

{array[$1$2] = $0

for(a in array)
if(<$0 is last record>) print array[a]}

but I don't know how to say "the last record". I tried with NR but it didn't really help...
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk: record has too many fields

Hi, I'm trying this command - but get this error. Do you guys have any workaround for this? cat tf|sed 's/{//g'|sed 's/,//g'|awk '{for (i=1;i<=NF;i++) {if ($i == "OPTIME") {k = i + 2; print $i,$k}}}' awk: record `2005 Jul 28 17:35:29...' has too many fields record number 15 This is how... (3 Replies)
Discussion started by: chaandana
3 Replies

2. Infrastructure Monitoring

Processing records as group - awk

I have a file has following records policy glb id 1233 name Permit ping from "One" to "Second" "Address1" "Any" "ICMP-ANY" permit policy id 999251 service "snmp-udp" exit policy glb id 1234 name Permit telnet from "One" to "Second" "Address2" "Any" "TCP-ANY" permit policy id 1234... (3 Replies)
Discussion started by: baskar
3 Replies

3. Shell Programming and Scripting

Print all the fields of record using awk

Hi, i want to generate print statement using awk. i have 20+ and 30+ fields in each line Now its priting only first eight fields print statement as output not all. my record is as shown below filename ... (2 Replies)
Discussion started by: raghavendra.nsn
2 Replies

4. Shell Programming and Scripting

Common records using AWK

Hi, To be honest, I am really impressed and amazed at the pace I find solutions for un-solved coding mysteries in this forum. I have a file like this input1.txt x y z 1 2 3 a b c 4 -3 7 k l m n 0 p 1 2 a b c 4 input2 x y z 9 0 -1 a b c 0 6 9 k l m 8 o p 1 2 a f x 9 Output... (9 Replies)
Discussion started by: jacobs.smith
9 Replies

5. Shell Programming and Scripting

Finding out the common lines in two files using 4 fields with the help of awk and UNIX

Dear All, I have 2 files. If field 1, 2, 4 and 5 matches in both file1 and file2, I want to print the whole line of file1 and file2 one after another in my output file. File1: sc2/80 20 . A T 86 F=5;U=4 sc2/60 55 . G T ... (1 Reply)
Discussion started by: NamS
1 Replies

6. Shell Programming and Scripting

awk - compare 1st 15 fields of record with 20 fields

I'm trying to compare 2 files for differences in a selct number of fields. When differnces are found it will write the whole record of the second file including appending '|C' out to a delta file. Each record will have 20 fields, but only want to do comparison of 1st 15 fields. The 1st field of... (7 Replies)
Discussion started by: sljnk
7 Replies

7. Shell Programming and Scripting

awk print matching records and occurences of each record

Hi all , I have two files : dblp.xml with dblp records and itu1.txt with faculty members records. I need to find out how many dblp records are related to the faculty members. More specific: I need to find out which names from itu1.txt are a match in dblp. xml file , print them and show how many... (4 Replies)
Discussion started by: iori
4 Replies

8. Shell Programming and Scripting

Sorting group of records and loading last record

Hi Everyone, I have below record set. File is fixed widht file 101newjersyus 20150110 101nboston us 20150103 102boston us 20140106 102boston us 20140103 I need to group record based on first 3 letters in our case(101 and 102) and sort last 8 digit in ascending order and print only... (4 Replies)
Discussion started by: patricjemmy6
4 Replies

9. Shell Programming and Scripting

Keeping record of file 2 based on a reference file 1 in awk

I have 2 input files (tab separated): file1: make_A 1990 foo bar make_B 2010 this that make_C 2004 these those file2: make_X 1970 1995 ref_1:43 ref_2:65 make_A 1970 1995 ref_1:4 ref_2:21 ref_3:18 make_A 1980 2002 ref_1:7 ref_2:7 ref_3:0 ... (2 Replies)
Discussion started by: beca123456
2 Replies

10. UNIX for Beginners Questions & Answers

Awk: group multiple fields from different records

Hi, My input looks like that: A|123|qwer A|456|tyui A|456|wsxe B|789|dfgh Using awk, I am trying to get: A|123;456|qwer;tyui;wsxe B|789|dfgh For records with same $1, group all the $2 in a field (without replicates), and all the $3 in a field (without replicates). What I have tried:... (6 Replies)
Discussion started by: beca123456
6 Replies
BUNDLE-UPDATE(1)														  BUNDLE-UPDATE(1)

NAME
bundle-update - Update your gems to the latest available versions SYNOPSIS
bundle update *gems [--source=NAME] DESCRIPTION
Update the gems specified (all gems, if none are specified), ignoring the previously installed gems specified in the Gemfile.lock. In gen- eral, you should use bundle install(1) bundle-install.1.html to install the same exact gems and versions across machines. You would use bundle update to explicitly update the version of a gem. OPTIONS
--source=<name> The name of a :git or :path source used in the Gemfile(5). For instance, with a :git source of http://github.com/rails/rails.git, you would call bundle update --source rails UPDATING ALL GEMS
If you run bundle update with no parameters, bundler will ignore any previously installed gems and resolve all dependencies again based on the latest versions of all gems available in the sources. Consider the following Gemfile(5): source "https://rubygems.org" gem "rails", "3.0.0.rc" gem "nokogiri" When you run bundle install(1) bundle-install.1.html the first time, bundler will resolve all of the dependencies, all the way down, and install what you need: Fetching source index for https://rubygems.org/ Installing rake (10.0.2) Installing abstract (1.0.0) Installing activesupport (3.0.0.rc) Installing builder (2.1.2) Installing i18n (0.4.1) Installing activemodel (3.0.0.rc) Installing erubis (2.6.6) Installing rack (1.2.1) Installing rack-mount (0.6.9) Installing rack-test (0.5.4) Installing tzinfo (0.3.22) Installing actionpack (3.0.0.rc) Installing mime-types (1.16) Installing polyglot (0.3.1) Installing treetop (1.4.8) Installing mail (2.2.5) Installing actionmailer (3.0.0.rc) Installing arel (0.4.0) Installing activerecord (3.0.0.rc) Installing activeresource (3.0.0.rc) Installing bundler (1.0.0.rc.3) Installing nokogiri (1.4.3.1) with native extensions Installing thor (0.14.0) Installing railties (3.0.0.rc) Installing rails (3.0.0.rc) Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed. As you can see, even though you have just two gems in the Gemfile(5), your application actually needs 25 different gems in order to run. Bundler remembers the exact versions it installed in Gemfile.lock. The next time you run bundle install(1) bundle-install.1.html, bundler skips the dependency resolution and installs the same gems as it installed last time. After checking in the Gemfile.lock into version control and cloning it on another machine, running bundle install(1) bundle-install.1.html will still install the gems that you installed last time. You don't need to worry that a new release of erubis or mail changes the gems you use. However, from time to time, you might want to update the gems you are using to the newest versions that still match the gems in your Gem- file(5). To do this, run bundle update, which will ignore the Gemfile.lock, and resolve all the dependencies again. Keep in mind that this process can result in a significantly different set of the 25 gems, based on the requirements of new gems that the gem authors released since the last time you ran bundle update. UPDATING A LIST OF GEMS
Sometimes, you want to update a single gem in the Gemfile(5), and leave the rest of the gems that you specified locked to the versions in the Gemfile.lock. For instance, in the scenario above, imagine that nokogiri releases version 1.4.4, and you want to update it without updating Rails and all of its dependencies. To do this, run bundle update nokogiri. Bundler will update nokogiri and any of its dependencies, but leave alone Rails and its dependencies. OVERLAPPING DEPENDENCIES
Sometimes, multiple gems declared in your Gemfile(5) are satisfied by the same second-level dependency. For instance, consider the case of thin and rack-perftools-profiler. source "https://rubygems.org" gem "thin" gem "rack-perftools-profiler" The thin gem depends on rack >= 1.0, while rack-perftools-profiler depends on rack ~> 1.0. If you run bundle install, you get: Fetching source index for https://rubygems.org/ Installing daemons (1.1.0) Installing eventmachine (0.12.10) with native extensions Installing open4 (1.0.1) Installing perftools.rb (0.4.7) with native extensions Installing rack (1.2.1) Installing rack-perftools_profiler (0.0.2) Installing thin (1.2.7) with native extensions Using bundler (1.0.0.rc.3) In this case, the two gems have their own set of dependencies, but they share rack in common. If you run bundle update thin, bundler will update daemons, eventmachine and rack, which are dependencies of thin, but not open4 or perftools.rb, which are dependencies of rack-perftools_profiler. Note that bundle update thin will update rack even though it's also a dependency of rack-perftools_profiler. In short, when you update a gem using bundle update, bundler will update all dependencies of that gem, including those that are also depen- dencies of another gem. In this scenario, updating the thin version manually in the Gemfile(5), and then running bundle install(1) bundle-install.1.html will only update daemons and eventmachine, but not rack. For more information, see the CONSERVATIVE UPDATING section of bundle install(1) bun- dle-install.1.html. RECOMMENDED WORKFLOW
In general, when working with an application managed with bundler, you should use the following workflow: o After you create your Gemfile(5) for the first time, run $ bundle install o Check the resulting Gemfile.lock into version control $ git add Gemfile.lock o When checking out this repository on another development machine, run $ bundle install o When checking out this repository on a deployment machine, run $ bundle install --deployment o After changing the Gemfile(5) to reflect a new or update dependency, run $ bundle install o Make sure to check the updated Gemfile.lock into version control $ git add Gemfile.lock o If bundle install(1) bundle-install.1.html reports a conflict, manually update the specific gems that you changed in the Gemfile(5) $ bundle update rails thin o If you want to update all the gems to the latest possible versions that still match the gems listed in the Gemfile(5), run $ bundle update March 2013 BUNDLE-UPDATE(1)
All times are GMT -4. The time now is 06:50 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy