Sponsored Content
Top Forums Shell Programming and Scripting Fetch lines from a file matching column2 of another file Post 302224767 by smriti_shridhar on Thursday 14th of August 2008 02:02:38 AM
Old 08-14-2008
Fetch lines from a file matching column2 of another file

Hi guys,
Please help me out in this problem. I have two files

FILE1
abc-23 : 4529675
cde-42 : 9824532
dge-91 : 1245367
gre-45 : 9824532
fgr-76 : 4529675

FILE2
4529675 : Gal Glu house-2-be
9824532 : cat mouse
1245367 : sirf surf-2-beta

where FILE2 is a static file with fixed contents.

I need an output file like this-

FILE3
abc-23 Gal Glu house-2-be
cde-42 cat mouse
dge-91 sirf surf-2-beta
gre-45 cat mouse
fgr-76 Gal Glu house-2-be

It should contain column 1 of FILE1 and column 2 of FILE2 where it matches column 2 of FILE1 with column 1 of FILE2.

Thanks.
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

delete lines in file matching a pattern

I have a text file, a sample of which is as follows: r/- * 0: WINDOWS/Microsoft.NET/Framework/v2.0.50727/ASP.NETWebAdminFiles/Images/headerGRADIENT_Tall.gif r/- * 0: WINDOWS/SoftwareDistribution/Download/cf8ec753e88561d2ddb53e183dc05c3e/backoff.jpg r/- * 0: ... (2 Replies)
Discussion started by: stumpyuk
2 Replies

2. Shell Programming and Scripting

How to print file without few exactly matching lines?

Hi I have a very long file with 4 columns of numbers for example 1875 1876 12725 12723 13785 13786 4232 4230 13184 13185 ... (2 Replies)
Discussion started by: ananyob
2 Replies

3. Shell Programming and Scripting

Print lines matching value(s) in other file using awk

Hi, I have two comma separated files. I would like to see field 1 value of File1 exact match in field 2 of File2. If the value matches, then it should print matched lines from File2. I have achieved the results using cut, paste and egrep -f but I would like to use awk as it is efficient way and... (7 Replies)
Discussion started by: SBC
7 Replies

4. Shell Programming and Scripting

Finding lines matching the Pattern and their previous lines in a file

Hi, I am trying to locate the occurences of certain pattern like 'Possible network disconnect' in a text file. I can get the actual lines matching the pttern using: grep -w 'Possible network disconnect' file_name. But I am more interested in getting the timing of these events which are... (7 Replies)
Discussion started by: sagarparadkar
7 Replies

5. Shell Programming and Scripting

Print matching lines in a file

Hello everyone, I have a little script below: die "Usage infile outfile reGex" if @ARGV != 3; ($regex) = @ARGV; open(F,$ARGV) or die "Can't open"; open(FOUT,"+>$ARGV") or die "Can't open"; while (<F>) { print FOUT if /$regex/.../$regex/; } No matter what I give $regex on the... (2 Replies)
Discussion started by: new bie
2 Replies

6. UNIX for Dummies Questions & Answers

FIND matching pattern of lines in a file

I need to search for two patterns in a file and find number of matching lines. find . -type f | xargs grep "DROP TABLE" | wc -l find . -type f | xargs grep "DROP SYNONYM" | wc -l The above code works. However I am looking at finding a commnd that will simplify as on a singe command... (2 Replies)
Discussion started by: Siva SQL
2 Replies

7. Shell Programming and Scripting

Substraction of matching lines from a file.

I have 2 files: file1.txt contains /html/mybook/Charts/143712/reptiles.pdf /html/mybook/Charts/198459/spices.pdf /html/mybook/Charts/198459/fresh_nuts.pdf /html/mybook/Charts/123457/dome_anim.pdf /html/mybook/Charts/123457/vegetables.pdf /html/content/3DInteractive/174091/CSPSGGB.html ... (6 Replies)
Discussion started by: Jojan Paul
6 Replies

8. Shell Programming and Scripting

awk to combine matching lines in file

I am trying to combine all matching lines in the tab-delimited using awk. The below runs but no output results. Thank you :). input chrX 110925349 110925532 ALG13 chrX 110925349 110925532 ALG13 chrX 110925349 110925532 ALG13 chrX 47433390 47433999 SYN1... (3 Replies)
Discussion started by: cmccabe
3 Replies

9. UNIX for Beginners Questions & Answers

awk to average matching lines in file

The awk below executes and is close (producing the first 4 columns in desired). However, when I add the sum of $7, I get nothing returned. Basically, I am trying to combine all the matching $4 in f1 and output them with the average of $7 in each match. Thank you :). f1 ... (2 Replies)
Discussion started by: cmccabe
2 Replies
PDIFF(1)								FSF								  PDIFF(1)

NAME
pdiff - produce a pretty comparison between files SYNOPSIS
pdiff FILE1 FILE2 [-- A2PS-OPTIONS...] DESCRIPTION
Pretty print the differences between FILE1 and FILE2. OPTIONS
-h, --help display this help and exit -v, --version display version information and exit -q, --quiet don't print informational messages -o, --output=FILE save the output in FILE Options for a2ps are given after `--', for instance $ pdiff COPYING COPYING.LIB -- -Pdisplay News, updates and documentation: http://www.inf.enst.fr/~demaille/a2ps/. AUTHOR
Written by Akim Demaille. REPORTING BUGS
Report bugs to <bug-a2ps@gnu.org>. COPYRIGHT
Copyright (C) 1997-1999 Akim Demaille, Miguel Santana This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICU- LAR PURPOSE. SEE ALSO
a2ps(1), card(1), fixps(1), pdiff(1), psset(1), texi2dvi4a2ps(1). The full documentation for pdiff is maintained as a Texinfo manual. If the info and pdiff programs are properly installed at your site, the command info pdiff should give you access to the complete manual. pdiff 0.4 (GNU a2ps 4.14) June 2014 PDIFF(1)
All times are GMT -4. The time now is 12:29 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy