Sponsored Content
Top Forums Shell Programming and Scripting awk should output if one input file doesnt have matching key Post 302313886 by pinnacle on Wednesday 6th of May 2009 09:14:57 PM
Old 05-06-2009
awk should output if one input file doesnt have matching key

Code:
nawk -F, 'FNR==NR{a[$1]= $3 ;next} $2 in a{print $1, 'Person',$2, a[$2]}' OFS=, filea fileb

Input filea
Quote:
Name,state,zip
david,va,25458
radha,tx,25254
vince,ny,25845
Input fileb
Quote:
id,Name
21,david
25,david
22,radha
23,surender
24,vince


output i am getting :
Quote:
output i am getting:
21,,david,25458
25,,david,25458
22,,radha,25254
24,,vince,25845

Quote:
Output wanted:
21,Person,david,25458
25,Person,david,25458
22,Person,radha,25254
23,Person,surender,
24,Person,vince,25845
 

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
HGVIEW(1)																 HGVIEW(1)

NAME
hgview - Qt based mercurial repository browser SYNOPSIS
hgview [options] [filename] DESCRIPTION
hgview(1) is a GUI application usually invoked from the command line. The simplest way to use it is to install it as a hg extension. Alternatively, it can be used as a standalone application. If [filename] is given, hgview will start in file-diff mode, in which user can easily compare arbitrary revisions of a file. Use ``hg help hgview`` for an extended help description OPTIONS
-n, --navigate (require a filename) starts in filelog navigation mode -r REV, --rev=REV starts in manifest mode for given revision FILES
~/.hgrc This is the standard file for configuring hg and its extensions. See hg qv-config for more details on what can be configured this way. ~/.hgusers This file holds configurations related to authors of patches in the hg repository. See hg qv-config for more details on what can be configured this way. BUGS
Please report any found bug on the mailing list or via email. Patches (or mercurial bundles) are always welcome. AUTHOR
Current version has been mainly written by David Douard <david.douard@logilab.fr[1]>, based on hgview 0.x code which has been written by Ludovic Aubry, Graziella Toutoungis and others. RESOURCES
http://www.logilab.org/project/hgview COPYRIGHT
Copyright (C) 2011 David Douard (david.douard@logilab.fr[1]). Copyright (C) 2007-2011 LOGILAB S.A. (Paris, FRANCE), http://www.logilab.fr/ -- mailto:contact@logilab.fr LICENSING
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this pro- gram; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. AUTHOR
David Douard <david.douard@logilab.fr> Author. NOTES
1. david.douard@logilab.fr mailto:david.douard@logilab.fr 05/29/2012 HGVIEW(1)
All times are GMT -4. The time now is 09:47 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy