Cross checking two files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Cross checking two files
# 1  
Old 05-04-2011
Cross checking two files

i have two files which contains some fields separated by columns as
Code:
03/29/1999           08:48:12            02          172.16.114.50
03/29/1999           09:08:00          480          172.16.112.100

Both of the files do have the same format
I want the script which will take two such files as input and give the output as the count of number of lines that exactly matched in both the files
How to deal with this?

thanks in advance
# 2  
Old 05-04-2011
Code:
grep -cf f1 f2

# 3  
Old 05-04-2011
Code:
awk 'NR==FNR{a[$0]; next}$0 in a{++c}END{print c}' file1 file2

# 4  
Old 05-04-2011
Hi,

Are you trying to match the content of file also?

Otherwise below code will work

#!/bin/bash
file1count=`cat file1 | wc -l`
file2count=`cat file2 | wc -l`
echo File1 $file1count
echo File2 $file2count

you can modify this code if you want to pass file name as argument.

Thanks,
Yagami
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Checking in a directory how many files are present and basing on that merge all the files

Hi, My requirement is,there is a directory location like: :camp/current/ In this location there can be different flat files that are generated in a single day with same header and the data will be different, differentiated by timestamp, so i need to verify how many files are generated... (10 Replies)
Discussion started by: srikanth_sagi
10 Replies

2. Shell Programming and Scripting

Checking dir and files!

Hi Guys, I wrote a code which checks for the text and directory. If the path is incorrect than it should echo that particular path not found. I can create a different if statments but I want to do this in just one if statment with the use of "or" (||). I have succssfully executed this code but now... (2 Replies)
Discussion started by: dixits
2 Replies

3. UNIX for Dummies Questions & Answers

Cross complie linux make files onto a windows 7 machine using PGI Cygwin

Hello, I am very unfamiliar with linux/unix (don't even know the difference), but am trying to get some linux software to run on my Windows machine for my research. I have the makefiles for the software, and it is designed to be compiled in the PGI complier, which I also have. When i... (6 Replies)
Discussion started by: roba87
6 Replies

4. Shell Programming and Scripting

awk cross-referencing between two files

I need to make my sloppy, existing code (non awk) more efficient and I seem to be terrible with awk :wall: I've tried around quite a bit, maybe you guys can conjure up a quick solution... file1: 2 SOL 563 2 SOL 565 3 SOL 589 2 SOL 603 1 SOL 612 1 SOL 621... (1 Reply)
Discussion started by: origamisven
1 Replies

5. Shell Programming and Scripting

checking thorough files and renamingit

hi all am very new to unix scripting..... i have a work right now that i should complete by End of Day :( scenario is i get some x number of files with .csv extension on a specified path at my operating system. the names of the files are as follows . the record lay out is same... (0 Replies)
Discussion started by: rajesh_tns
0 Replies

6. UNIX for Dummies Questions & Answers

Checking files extension

Hi, I need one line command to display all files that ends with .scr. Example: In a directory I have 10 files, out of that 4 files have filetype extension .dat and 4 files with .scr and 2 files with .txt.... In this i want to display only files that ends with .scr. I tried some commands,... (2 Replies)
Discussion started by: gwgreen1
2 Replies

7. Shell Programming and Scripting

files cross over

I have many files (File 1, File 2, File 3, ...) in same directory. The format of all these files are same. What I would like to do is to combine all these files into a single file via cross over. Example) >>File 1 look like this. f1 01 1.0 f1 02 2.0 f1 03 3.0 f1 04 4.0 f1 05 5.0 f1 06... (2 Replies)
Discussion started by: Jae
2 Replies

8. UNIX for Advanced & Expert Users

how to login into another ip and checking for the files

Hi All, Good Day. need one help regarding unix script. i have to check whether the particular file is there or not in another ip address. suppose....there is file in this ip address 2.160.64.130 in particualar location. i have to veify this from another ip adress(Say 2.160.64.131).if the file... (1 Reply)
Discussion started by: saikumar_n
1 Replies

9. UNIX for Dummies Questions & Answers

checking for files on ftp...

I have automated my ftp session as given in on of the previous threads as: #! /usr/bin/ksh HOST=remote.host.name USER=whoever PASSWD=whatever exec 4>&1 ftp -nv >&4 2>&4 |& print -p open $HOST print -p user $USER $PASSWD print -p cd directory print -p binary print -p get xyz wait... (3 Replies)
Discussion started by: jithinravi
3 Replies
Login or Register to Ask a Question