Sponsored Content
Top Forums Shell Programming and Scripting Comparing the values of two files Post 302808413 by Yoda on Thursday 16th of May 2013 04:38:54 PM
Old 05-16-2013
I noticed that you used a lot of external utilities like cat, grep, awk, cut when most of these tasks can be done by shell built-ins.

Always use shell built-ins where ever possible, it will help significantly improve the performance of your script.

I'm not sure if I understood your requirement correctly, but see few corrections and suggestions below:
Code:
#!/bin/ksh

while read s_id_1 s_id_2
do
        FLAG=0
        while read b_id_1 b_id_2
        do
                if [ $s_id_1 -eq $b_id_1 ]
                then
                        print "The value in small file is $s_id_2 and in big file is $b_id_2"
                        FLAG=1
                fi
        done < BigFile

        [ $FLAG -eq 0 ] && print "Cannot find a match for $s_id_1"

done < SmallFile

This User Gave Thanks to Yoda For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

comparing PID values of 2 Files in shell Options

Hi, There is a file having a list of running PIDs and another file having a list of registered PIDs. How can we check if each value of running PIDs are less or more than the registered PIDs i.e. comparing the value of each PID in both the files. Request you to pls give your inputs. ... (2 Replies)
Discussion started by: marconi
2 Replies

2. Shell Programming and Scripting

comparing values of same variable

Hello all while writing a small script , i got stuck with this simple thing.Hope you guyz can help. Iam trying to read password echo"enter password" read $pwd now i have to check this echo"enter password to proceed" read $pwd now i have to check both the values of the... (2 Replies)
Discussion started by: coolkid
2 Replies

3. Shell Programming and Scripting

comparing 2 text files to get unique values??

Hi all, I have got a problem while comparing 2 text files and the result should contains the unique values(Non repeatable). For eg: file1.txt 1 2 3 4 file2.txt 2 3 So after comaping the above 2 files I should get only 1 and 4 as the output. Pls help me out. (7 Replies)
Discussion started by: smarty86
7 Replies

4. Shell Programming and Scripting

comparing values

i have two file and i am comparing both.. in cmp1 ,the content is : the nu of file is : <some integer value> in cmp2 ,the content is : the nu of file is : so want a script which will take value (2) when cmp1 is compared with cmp2.. i mean cmp cmp1 cmp2 the the output will be he nu of... (1 Reply)
Discussion started by: Aditya.Gurgaon
1 Replies

5. Shell Programming and Scripting

Comparing values in column 1

Hi to all, I have the following text within inputfile data1,value1,value2 data1,value3,value2 data1,value5,value6 data2,value1,value2 data2,value3,value4 data3,value1,value2 data3,value3,value4 data4,value1,value2 data4,value3,value4 data4,value5,value6 I would like to... (4 Replies)
Discussion started by: cgkmal
4 Replies

6. UNIX for Dummies Questions & Answers

Comparing two files and dividing the values

Hi all, I am new to unix and I am trying hard to get this requirement, but no luck. I am trying to compare two cloumns in two files and if it matches, the last column in file1 must be divided by file2 and the output must be written in a new file. To elaborate the 2nd column in file1 (EUR) must be... (6 Replies)
Discussion started by: smadderla
6 Replies

7. UNIX for Dummies Questions & Answers

Comparing two text files by a column and printing values that do not match

I have two text files where the first three columns are exactly the same. I want to compare the fourth column of the text files and if the values are different, print that row into a new output file. How do I go about doing that? File 1: 100 rs3794811 0.01 0.3434 100 rs8066551 0.01... (8 Replies)
Discussion started by: evelibertine
8 Replies

8. UNIX for Dummies Questions & Answers

Comparing two test files and printing out the values that do not match

Hi, I have two text files with matching first columns. Some of the values in the second column do not match. I want to write a script to print out the rows (only the first column) where the values in the second column do not match. Example: Input 1 A 1 B 2 C 3 D 4 Input 2 A 2 B 2... (6 Replies)
Discussion started by: evelibertine
6 Replies

9. Shell Programming and Scripting

Comparing same column from two files, printing whole row with matching values

First I'd like to apologize if I opened a thread which is already open somewhere. I did a bit of searching but could quite find what I was looking for, so I will try to explaing what I need. I'm writing a script on our server, got to a point where I have two files with results. Example: File1... (6 Replies)
Discussion started by: mitabrev83
6 Replies

10. Shell Programming and Scripting

Extracting and comparing values

I was trying to extract value of g1 and p1 only inside the tags where t1 is "Reading C (bytes)" and comparing them to make sure p1 is always less than g1. Here is the Json file I'm using - File:- { "g1" : 1482568, "n1" : "v_4", "p1" : 0, "s1" : "RC", "t1" : "LM", } { "g1" :... (3 Replies)
Discussion started by: Mannu2525
3 Replies
AnyDBM_File(3pm)					 Perl Programmers Reference Guide					  AnyDBM_File(3pm)

NAME
AnyDBM_File - provide framework for multiple DBMs NDBM_File, DB_File, GDBM_File, SDBM_File, ODBM_File - various DBM implementations SYNOPSIS
use AnyDBM_File; DESCRIPTION
This module is a "pure virtual base class"--it has nothing of its own. It's just there to inherit from one of the various DBM packages. It prefers ndbm for compatibility reasons with Perl 4, then Berkeley DB (See DB_File), GDBM, SDBM (which is always there--it comes with Perl), and finally ODBM. This way old programs that used to use NDBM via dbmopen() can still do so, but new ones can reorder @ISA: BEGIN { @AnyDBM_File::ISA = qw(DB_File GDBM_File NDBM_File) } use AnyDBM_File; Having multiple DBM implementations makes it trivial to copy database formats: use POSIX; use NDBM_File; use DB_File; tie %newhash, 'DB_File', $new_filename, O_CREAT|O_RDWR; tie %oldhash, 'NDBM_File', $old_filename, 1, 0; %newhash = %oldhash; DBM Comparisons Here's a partial table of features the different packages offer: odbm ndbm sdbm gdbm bsd-db ---- ---- ---- ---- ------ Linkage comes w/ perl yes yes yes yes yes Src comes w/ perl no no yes no no Comes w/ many unix os yes yes[0] no no no Builds ok on !unix ? ? yes yes ? Code Size ? ? small big big Database Size ? ? small big? ok[1] Speed ? ? slow ok fast FTPable no no yes yes yes Easy to build N/A N/A yes yes ok[2] Size limits 1k 4k 1k[3] none none Byte-order independent no no no no yes Licensing restrictions ? ? no yes no [0] on mixed universe machines, may be in the bsd compat library, which is often shunned. [1] Can be trimmed if you compile for one access method. [2] See DB_File. Requires symbolic links. [3] By default, but can be redefined. SEE ALSO
dbm(3), ndbm(3), DB_File(3), perldbmfilter perl v5.12.1 2010-04-26 AnyDBM_File(3pm)
All times are GMT -4. The time now is 08:07 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy