Sponsored Content
Top Forums Shell Programming and Scripting awk should output if one input file doesnt have matching key Post 302314047 by pinnacle on Thursday 7th of May 2009 09:29:33 AM
Old 05-07-2009
Quote:
Originally Posted by devtakh
Try this:

Code:
awk -F "," 'FNR==NR && NR>1{a[$1]=$3;next}FNR>1{if ($2 in a)print $1,"Person",$2,a[$2]; else print $1,"Person",$2 OFS}' OFS="," filea fileb


cheers,
Devaraj Takhellambam

Thank you sir
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Pass input and output file as parameter to awk script

Hi, i am new to awk. I am using csv2pipe script(shown below) BEGIN { FS=SUBSEP; OFS="|" } { result = setcsv($0, ",") print } # setcsv(str, sep) - parse CSV (MS specification) input # str, the string to be parsed. (Most likely $0.) # sep, the separator between the values. # #... (6 Replies)
Discussion started by: bhaskarjha178
6 Replies

2. Shell Programming and Scripting

Dynamic output file generation using a input text file with predefined output format

Hi, I have two files , one file with data file with attributes that need to be sent to another file to generate a predefined format. Example: File.txt AP|{SSHA}VEEg42CNCghUnGhCVg== APVG3|{SSHA}XK|"password" AP3|{SSHA}XK|"This is test" .... etc --------- test.sh has... (1 Reply)
Discussion started by: hudson03051nh
1 Replies

3. Shell Programming and Scripting

AWK Script to convert input file(s) to output file

Hi All, I am hoping someone can help me with some scripting I need to complete using AWK. I'm trying to process multiple fixed files to generate one concatenated fixed file in a standard format. The Input file is:- aaaa bbbbb ccccc 1 xxxx aaa bbb aaaa bbbbb ccccc 2 abcd aaa CCC... (9 Replies)
Discussion started by: jason_v_brown
9 Replies

4. Shell Programming and Scripting

Using AWK to format output based on key field

I have file which contains gene lines something like this Transcript Name GO POPTR_0016s06290.1 98654 POPTR_2158s00200.1 11324 POPTR_0004s22390.1 12897 POPTR_0001s11490.1 POPTR_0016s13950.1 14532 POPTR_0015s05840.1 13455 POPTR_0013s06470.1 12344... (6 Replies)
Discussion started by: shen
6 Replies

5. Shell Programming and Scripting

awk file comparison, x lines after matching as output

Hello, I couldn't find anything on the Forum that would help me to solve this problem. Could any body help me process below data using awk? I have got two files: file1: Worker1: Thomas Position: Manager Department: Sales Salary: $5,000 Worker2: Jason Position: ... (5 Replies)
Discussion started by: killerbee
5 Replies

6. UNIX for Dummies Questions & Answers

awk - Rename output file, after processing, same as input file

I have one input file ABC.txt and one output DEF.txt. After the ABC is processed and created output, I want to rename ABC.txt to ABC.orig and DEF to ABC.txt. Currently when I am doing this, it does not process the input file as it cannot read and write to the same file. How can I achieve this? ... (12 Replies)
Discussion started by: High-T
12 Replies

7. UNIX for Dummies Questions & Answers

awk - Print lines if only matching key is found

I am looking to move matching lines (01 - 07) from File1 and 77 tab the matching string from File2, to File3.txt. I am almost done but - Currently, script is not printing lines to File3.txt in order. Thanks a lot. Any help is appreciated. Script I am using: awk 'FNR == NR && ! /^]*$/ {... (9 Replies)
Discussion started by: High-T
9 Replies

8. UNIX for Dummies Questions & Answers

Redirect output to the same input file in awk

Hi, I want to compare a value from test file and redirect the o/p value to the same file input file 250 32000 32 128 Below is my code awk '{ if ($1 < "300") print $1 > /tmp/test}' test want to compare 250 < 300 then print 300 to the same place below is the... (24 Replies)
Discussion started by: stew
24 Replies

9. UNIX for Dummies Questions & Answers

File updation on matching key

I have input file like Input.dat with below content RRD 0Z91YUn000000Lk 9000100001 103020151117 STMT151117155527001 0000 2 000000 000004 RRD 0Z91YUn00000ysj 9000100001 103020151117 STMT151117155527001 0000 3 000000 000003 RRD 0Z91YUn00001vGh 9000100002... (12 Replies)
Discussion started by: PRAMOD 96
12 Replies

10. Shell Programming and Scripting

awk to reformat output if input file is empty, but not if file has data in it

The below awk improved bu @MadeInGermany, works great as long as the input file has data in it in the below format: input chrX 25031028 25031925 chrX:25031028-25031925 ARX 631 18 chrX 25031028 25031925 chrX:25031028-25031925 ARX 632 14... (3 Replies)
Discussion started by: cmccabe
3 Replies
Moose::Manual::Classes(3pm)				User Contributed Perl Documentation			       Moose::Manual::Classes(3pm)

NAME
Moose::Manual::Classes - Making your classes use Moose (and subclassing) VERSION
version 2.0603 USING MOOSE
Using Moose is very simple, you just "use Moose": package Person; use Moose; That's it, you've made a class with Moose! There's actually a lot going on here under the hood, so let's step through it. When you load Moose, a bunch of sugar functions are exported into your class, such as "extends", "has", "with", and more. These functions are what you use to define your class. For example, you might define an attribute ... package Person; use Moose; has 'ssn' => ( is => 'rw' ); Attributes are described in the Moose::Manual::Attributes documentation. Loading Moose also enables the "strict" and "warnings" pragmas in your class. When you load Moose, your class will become a subclass of Moose::Object. The Moose::Object class provides a default constructor and destructor, as well as object construction helper methods. You can read more about this in the Moose::Manual::Construction document. As a convenience, Moose creates a new class type for your class. See the Moose::Manual::Types document to learn more about types. It also creates a Moose::Meta::Class object for your class. This metaclass object is now available by calling a "meta" method on your class, for example "Person->meta". The metaclass object provides an introspection API for your class. It is also used by Moose itself under the hood to add attributes, define parent classes, and so on. In fact, all of Moose's sugar does the real work by calling methods on this metaclass object (and other meta API objects). SUBCLASSING
Moose provides a simple sugar function for declaring your parent classes, "extends": package User; use Moose; extends 'Person'; has 'username' => ( is => 'rw' ); Note that each call to "extends" will reset your parents. For multiple inheritance you must provide all the parents at once, "extends 'Foo', 'Bar'". You can use Moose to extend a non-Moose parent. However, when you do this, you will inherit the parent class's constructor (assuming it is also called "new"). In that case, you will have to take care of initializing attributes manually, either in the parent's constructor, or in your subclass, and you will lose a lot of Moose magic. See the MooseX::NonMoose module on CPAN if you're interested in extending non-Moose parent classes with Moose child classes. CLEANING UP MOOSE DROPPINGS
Moose exports a number of functions into your class. It's a good idea to remove these sugar functions from your class's namespace, so that "Person->can('has')" will no longer return true. There are several ways to do this. We recommend using namespace::autoclean, a CPAN module. Not only will it remove Moose exports, it will also remove any other exports. package Person; use namespace::autoclean; use Moose; If you absolutely can't use a CPAN module (but can use Moose?), you can write "no Moose" at the end of your class. This will remove any Moose exports in your class. package Person; use Moose; has 'ssn' => ( is => 'rw' ); no Moose; MAKING IT FASTER
Moose has a feature called "immutabilization" that you can use to greatly speed up your classes at runtime. However, using it incurs a cost when your class is first being loaded. When you make your class immutable you tell Moose that you will not be changing it in the future. You will not be adding any more attributes, methods, roles, etc. This allows Moose to generate code specific to your class. In particular, it creates an "inline" constructor, making object construction much faster. To make your class immutable you simply call "make_immutable" on your class's metaclass object. __PACKAGE__->meta->make_immutable; Immutabilization and "new()" If you override "new()" in your class, then the immutabilization code will not be able to provide an optimized constructor for your class. Instead, you should use a "BUILD()" method, which will be called from the inlined constructor. Alternately, if you really need to provide a different "new()", you can also provide your own immutabilization method. Doing so requires extending the Moose metaclasses, and is well beyond the scope of this manual. AUTHOR
Moose is maintained by the Moose Cabal, along with the help of many contributors. See "CABAL" in Moose and "CONTRIBUTORS" in Moose for details. COPYRIGHT AND LICENSE
This software is copyright (c) 2012 by Infinity Interactive, Inc.. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. perl v5.14.2 2012-06-28 Moose::Manual::Classes(3pm)
All times are GMT -4. The time now is 09:34 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy