File Reference Matching


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting File Reference Matching
# 1  
Old 07-10-2015
File Reference Matching

Hi,

I need help with the below scenario in Bash scripting:

I have two files:
tmp.orig with the below contents
Code:
"TEST1"
"TEST2"
"TEST5"
"TEST6"

and tmp.new with below contents
Code:
"TEST1;921"
"TEST2;34"
"TEST3;2"
"TEST4;33"
"TEST5;98"
"TEST6;1"

I need to run tmp.orig against tmp.new and match the characters while generating the below output:
Code:
"TEST1;921"
"TEST2;34"
"TEST5;98"
"TEST6;1"

I would greatly appreciate your help.
Note: Although the problem is real, these are dummy values and filenames.

Thanks.

Last edited by Don Cragun; 07-10-2015 at 06:22 PM.. Reason: Add CODE and ICODE tags.
# 2  
Old 07-10-2015
This is pretty similar to the thread you posted in 2009: Matching key fields

What have you tried to solve this problem on your own?

What operating system are you using?
# 3  
Old 07-10-2015
Yeah, that code is not going to work here. This is bash in Sun OS, and that was ksh in AIX.
# 4  
Old 07-10-2015
I repeat: "What have you tried to solve this problem on your own?"
This User Gave Thanks to Don Cragun For This Post:
# 5  
Old 07-11-2015
Quote:
Originally Posted by ChicagoBlues
Yeah, that code is not going to work here. This is bash in Sun OS, and that was ksh in AIX.
If i read the code in the mentioned other thread correctly the suggestion was to use

Code:
fgrep -f <file-with-keys> <file-to-search>

Which part of this is shell-dependent? Have you even read the other thread?

bakunin
# 6  
Old 07-11-2015
Quote:
Originally Posted by bakunin
If i read the code in the mentioned other thread correctly the suggestion was to use

Code:
fgrep -f <file-with-keys> <file-to-search>

Which part of this is shell-dependent? Have you even read the other thread?

bakunin
The fgrep solution from that thread won't work exactly because the quotes in the files won't match properly.

There was also an awk suggestion in that thread. It won't work exactly either, but would be a good starting point if the field separators were modified.

I had just hoped that with our help in processing 41 requests over these last 7.5 years, ChicagoBlues would be willing to show us that some attempt had been made to come up with a solution for this relatively simple task before using the UNIX & Linux Forums as an unpaid programming staff. (However, I am disappointed at some of the suggestions that have been given to ChicagoBlues over the years.)
This User Gave Thanks to Don Cragun For This Post:
# 7  
Old 07-11-2015
Quote:
Originally Posted by Don Cragun
The fgrep solution from that thread won't work exactly because the quotes in the files won't match properly.
You are right and i perhaps should have done a better job of expressing myself. Regardless of the solution being usable as is or only after some tweaking

Code:
fgrep -f <file-with-keys> <file-to-search>

or any variation thereof will be independent of the shell employed. Therefore the mentioning

Quote:
This is bash in Sun OS, and that was ksh in AIX.

was about as astute as "yes, but it was mentioned on a Friday and today is Saturday".


Quote:
Originally Posted by Don Cragun
There was also an awk suggestion in that thread. It won't work exactly either, but would be a good starting point if the field separators were modified.
Absolutely correct, but this (or any solution derived from it) would have nothing to do with the shell or the system - just with the willingness to undergo the effort to actually modify it into a fitting form.

Quote:
Originally Posted by Don Cragun
I had just hoped that with our help in processing 41 requests over these last 7.5 years, ChicagoBlues would be willing to show us that some attempt had been made to come up with a solution for this relatively simple task before using the UNIX & Linux Forums as an unpaid programming staff. (However, I am disappointed at some of the suggestions that have been given to ChicagoBlues over the years.)
Spot on on both accounts!

bakunin
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Solaris 11 patch cross reference file

Hi all I wanted to know does solaris 11 have any place to download patch cross-reference file like solaris 10 (h t t p s://getupdates.oracle.com/reports/patchdiag.xref)? I wanted to use this file to filter out those security patches and use it to check if any of my solaris 11 systems are... (0 Replies)
Discussion started by: kaze
0 Replies

2. UNIX for Dummies Questions & Answers

awk to replace values in one file using a second reference file

Hi, I'd be grateful for your help with the following: I have a file with a single column (file1). Let's say the values are: a b c 5 d I have a second, reference file (ref_file), which is colon-delimited, and is effectively a key. Let's say the values in it are: a:1 b:2 c:3 d:4... (4 Replies)
Discussion started by: aberg
4 Replies

3. Shell Programming and Scripting

Compare data with reference from other file

Gents, Please can you help with this. I have a big file (file2) which contends many records increment every 25 rows ( column 1 ). Then I have other file as reference (file1).. column 1 to 11. I want to compare that all values in file2 (column 2 to 12.) match with values in... (2 Replies)
Discussion started by: jiam912
2 Replies

4. Shell Programming and Scripting

Reading reference file

For file purge and archive script, I am planing to have the reference files as below for various file system. >ReferenceFile.cfg ... ... DailyArchive: { FOLDERS PATERN DAYS_TO_RETAIN MINIMUM_SIZE_THESHOLD(MB) /aaa/bbb/ * 3 300... (4 Replies)
Discussion started by: deepakwins
4 Replies

5. 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

6. Shell Programming and Scripting

Replace a value using a reference data from other file

Gents, Can you please help me to solve this case In my input file I have a values in column 49 which always need to be one, but sometimes the system create a value 2, in this case I need to go to search in the original file and replace the values in the row where the value 2 is and in the... (6 Replies)
Discussion started by: jiam912
6 Replies

7. Shell Programming and Scripting

Replace from reference file awk

Basically want to replace any field in input file from the refernce file ... for example. clar_2400:3113 in input file will be replaced by clar_2400:3113 Input file field seperator is "," Field which is not found in reference will stay as it is ... Input File ... (3 Replies)
Discussion started by: greycells
3 Replies

8. Shell Programming and Scripting

Perl de-reference code reference variable

Guys, May i know how can we de reference the code reference variable.? my $a = sub{$a=shift;$b=shift;print "SUM:",($a+$b),"\n";}; print $a->(4,5); How can we print the whole function ? Please suggest me regarding this. Thanks for your time :) Cheers, Ranga :) (0 Replies)
Discussion started by: rangarasan
0 Replies

9. Programming

Help to filter read through reference file by using c language

Input_file #tmp_2 werweraewghe @tmp_2 123sdfs57a #tmp_1 aewrgheheghe @tmp_1 457awrerfa87 #tmp_4 trtyrghe @tmp_4 8898rtyr2 reference_file #tmp_4 #tmp_1 (14 Replies)
Discussion started by: cpp_beginner
14 Replies

10. Shell Programming and Scripting

Help with replace column one content based on reference file

Input file 1 testing 10 20 1 A testing 20 40 1 3 testing 23 232 2 1 testing 10 243 2 . . Reference file 1 final 3 used . . Output file (1 Reply)
Discussion started by: perl_beginner
1 Replies
Login or Register to Ask a Question