Sponsored Content
Top Forums Shell Programming and Scripting Creating a file with matching records from two other files Post 302381127 by ichigo on Thursday 17th of December 2009 08:41:57 AM
Old 12-17-2009
Code:
gawk -F"," 'FNR==NR{a[$1]=$0;next}
{ for(o=1;o<=NF;o++){ 
       if($o in a) { 
              print a[$o];print 
              break 
       }
   }
}' file1 file2

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How can you delete records in a file matching a pattern?

I am curious if the following can be done in a file in unix. Let's say I have a flat file with the following data AAA,12,2,,,, BBB,3,1,,,, CCC,,,,, DDD,2,,,,, SQQ,,,,, ASJ,,3,5 I only want to capture the data with values into a new file. If the data contains the pattern ,,,,, as in... (2 Replies)
Discussion started by: mode09
2 Replies

2. Shell Programming and Scripting

Removing non matching records

Hi all I have a file with records starting with "Page" has a first column. some of the records have some other junk characters has first column. so pls help me to remove rows which is not having "Page" has a first column. Thanks, Baski (2 Replies)
Discussion started by: baskivs
2 Replies

3. Shell Programming and Scripting

Compare two files with different number of records and output only the Extra records from file1

Hi Freinds , I have 2 files . File 1 |nag|HYd|1|Che |esw|Gun|2|hyd |pra|bhe|3|hyd |omu|hei|4|bnsj |uer|oeri|5|uery File 2 |nag|HYd|1|Che |esw|Gun|2|hyd |uer|oi|3|uery output : (9 Replies)
Discussion started by: i150371485
9 Replies

4. Shell Programming and Scripting

Creating single pattern for matching multiple files.

Hi friends, I have a some files in a directory. for example 856-abc 856-def 851-abc 945-def 956-abc 852-abc i want to display only those files whose name starts with 856* 945* and 851* using a single pattern. i.e 856-abc 856-def 851-abc 945-def the rest of the two files... (2 Replies)
Discussion started by: Little
2 Replies

5. Shell Programming and Scripting

Listing the file name and no of records in each files for the files created on a specific day

Hi, I want to display the file names and the record count for the files in the 2nd column for the files created today. i have written the below command which is listing the file names. but while piping the above command to the wc -l command its not working for me. ls -l... (5 Replies)
Discussion started by: Showdown
5 Replies

6. Shell Programming and Scripting

Performance of calculating total number of matching records in multiple files

Hello Friends, I've been trying to calculate total number of a certain match in multiple data records files (DRs). Let say I have a daily created folders for each day since the beginning of july like the following drwxrwxrwx 2 mmsuper med 65536 Jul 1 23:59 20150701 drwxrwxrwx 2 mmsuper... (1 Reply)
Discussion started by: EAGL€
1 Replies

7. Shell Programming and Scripting

Shell script to filter records in a zip file that contains matching columns from another file

Not sure if this is the correct forum for this question. I have two files. file1.zip, file2 Input: file1.zip col1, col2 , col3 a , b , 0:0:0:0:0:c436:9346:d40b x, y, 0:0:0:0:0:880:39f9:c9a7 m, n , 0:0:0:0:0:80c7:9161:fe00 file2.txt col1 c4:36:93:46:d4:0b... (1 Reply)
Discussion started by: anil.v
1 Replies

8. Shell Programming and Scripting

How can I retrieve the matching records from data file mentioned?

XYZNA0000778800Z 16123000012300321000000008000000000000000 16124000012300322000000007000000000000000 17234000012300323000000005000000000000000 17345000012300324000000004000000000000000 17456000012300325000000003000000000000000 9 XYZNA0000778900Z 16123000012300321000000008000000000000000... (8 Replies)
Discussion started by: later_troy
8 Replies

9. UNIX for Beginners Questions & Answers

Matching fields between two files, repeated records

In two previous posts (here) and (here), I received help from forum members comparing multiple fields across two files and selectively printing portions of each as output based upon would-be matches using awk. I had been fairly comfortable populating awk arrays with fields and using awk's special... (3 Replies)
Discussion started by: jvoot
3 Replies

10. UNIX for Beginners Questions & Answers

awk for matching fields between files with repeated records

Hello all, I am having trouble with what should be an easy task, but seem to be missing something fundamental. I have two files, with File 1 consisting of a single field of many thousands of records. I also have File 2 with two fields and many thousands of records. My goal is that when $1 of... (2 Replies)
Discussion started by: jvoot
2 Replies
gt5(1)							      General Commands Manual							    gt5(1)

NAME
gt5 - a diff-capable 'du-browser' SYNOPSIS
gt5 [ dir | file | dir file | file file2 ] [options] DESCRIPTION
gt5 reads the output of du, compares it with a du-log saved by the last run, converts it into HTML and opens the resulting file with a textbrowser. If files are given on the commandline they are expected to be (optionally gzip/bzip2-compressed) logfiles of du -akx /some/dir. It is up to you to take care that the given directories/files represent the same directory. gt5 will show lots of new files if you don't. ;-) OPTIONS
--cut-at float Files and directories that are below float percent of their parents are not shown. Default is 0.1, gt5 will accept values between 0.01 and 30. --debug Turn on debug. Generate HTML files and do not run browser. --diff-dir directory Use directory instead of ~/.gt5-diffs/ to read/store du-logs. This switch is ignored if gt5 is only used with files. --discard Do not save the current state, in other words: be able to diff against the old state again. This feature is disabled if gt5 is only used with files. --help Display brief help. --link-files Also insert links to files to access them from within gt5. This can be very handy if your browser is configured to handle the files MIME-type correctly. This feature is disabled if gt5 is only used with files. --max-depth int Do not show anything below a depth of int directories. Default is 5 (also see BUGS below). --max-lines int Only consider the int biggest files and directories within the output of du. --no-diffs Use this if you are not interested in the history of the directories processed, for example in /tmp. --save-as file DEPRECATED, use du -akx or du -ak (see --with-mounts), save the output to a file and run gt5 against one (ore two) of these files later. --save-state Force saving current state, overwriting a previous --discard. (Some people seem to have gt5 aliased to 'gt5 --discard'.) --verbose Display messages. --with-mounts By default gt5 calls du with -akx to ignore mounted filesystems. Use this to inspect mounted partitions too, i.e. call du with -ak HELPERS
If gawk or a textbrowser are missing and you want to install them into ~/bin (or /usr/local/bin if you have write access there), gt5 comes with the following helpers: --get-gawk Download, compile and install a copy of gawk. --get-links Download, compile and install a copy of links. --get-links2 Download, compile and install a copy of links2. --get-elinks Download, compile and install a copy of elinks. TEXTBROWSERS
It is recommended to use links with gt5. Other textbrowsers are also possible but there are several good reasons why links is given prior- ity over the others: elinks: links is much faster on startup/exit lynx: does not honor a documents coloring netrik: no colors, unfavourable cursor navigation retawq: no colors, can't handle <a name>-tags w3m: Version 0.5.2 and later are known to work. Older versions experienced unfavourable handling of <a name>-tag, unfavourable cursor navigation and no colors Only links/links2, elinks and lynx are now considered usable (and also chosen in that order). See ENVIRONMENT/GT5_BROWSER below. FILES
~/.gt5.html contains a copy of the last run ~/.gt5-diffs/ compressed du-logs are stored here ENVIRONMENT
GT5_BROWSER force using a (specific) textbrowser GT5_CHARSET force using a (specific) charset for HTML header instead of using $LANG GT5_DEBUG_DIR Directory where to write gt5.debug* data if --debug option is set. BUGS
Directories at depth max-depth are not browsable and so look like files. AUTHOR
Thomas Sattler <gt5 at gmx dot net> SEE ALSO
du(1), links(1), elinks(1), lynx(1) gt5 v1.4.0.1 July 2009 gt5(1)
All times are GMT -4. The time now is 12:48 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy