Comparing data inside file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Comparing data inside file
# 1  
Old 06-18-2008
Comparing data inside file

Hi Everyone,

I will try to explain my question please forgive my english here.

I am looking for shell script or command that can compare data in the files.

I have 50 files in one directory test1 test2 test3 ....so on.

I want to compare data in each files with each other and output each line with same data in one file.

so each file contain extactly same data but the bytes are different

so for example of three files data:

data in test1:

Code:
-ommuniGate,1,7659,96
-me/abhiram,1,7615,96
-me/ahonnik,1,7610,96
-home/aleda,0,134307,67936
-/home/apps,1,323610,79168
-me/archive,1,7611,96
-/home/atmf,0,7613,96
-/home/baja,1,8431,352
-ome/bbcron,0,7639,96
-home/bbjen,0,8129,224
-/home/bcdf,0,7810,128
-/home/beth,0,7670,96
-/home/bing,1,206505,55232
-home/blinn,0,1167752,412608
-e/bmandell,0,7683,96
-0/home/bob,1,7631,96
-home/bobby,1,31936,11680
-ome/cadams,0,48664,28224
-me/cbaxter,1,7615,96
-me/cjensen,0,7642,96
-ome/cklang,1,7615,96
-me/ckohler,1,7682,128
-e/cmargozz,0,35436,17888
-e/cpitcher,1,7615,96
-e/cschroff,0,8571,352
-ome/cyoung,1,7615,96
-ome/daniel,0,171547,53024

data in test2:
Code:
-ommuniGate,1,7717,96
-me/abhiram,1,7615,96
-me/ahonnik,1,7610,96
-home/aleda,1,7611,96
-/home/apps,1,323653,79168
-me/archive,1,115224,106912
-/home/atmf,1,7611,96
-/home/baja,1,8634,384
-ome/bbcron,1,7611,96
-home/bbjen,1,7611,96
-/home/bcdf,1,7611,96
-/home/beth,1,7615,96
-/home/bing,1,207685,55360
-home/blinn,1,7620,96
-e/bmandell,1,7611,96
-0/home/bob,1,7631,96
-home/bobby,1,31936,11680
-ome/cadams,1,7611,96
-me/cbaxter,1,7615,96
-me/cjensen,1,7611,96
-ome/cklang,1,7615,96
-me/ckohler,1,7682,128
-e/cmargozz,1,7611,96
-e/cpitcher,1,7615,96
-e/cschroff,1,7611,96
-ome/cyoung,1,7615,96
-ome/daniel,1,7622,96

data in test 3:

Code:
-ommuniGate,1,261840,134880
-me/abhiram,1,7615,96
-me/ahonnik,1,7610,96
-home/aleda,1,7611,96
-/home/apps,1,328804,80384
-me/archive,1,115224,106912
-/home/atmf,1,7611,96
-/home/baja,1,25709,9888
-ome/bbcron,1,7611,96
-home/bbjen,1,7611,96
-/home/bcdf,1,7611,96
-/home/beth,1,7615,96
-/home/bing,1,217811,58944
-home/blinn,1,7620,96
-e/bmandell,1,7611,96
-0/home/bob,1,101510,17120
-home/bobby,1,67032,28544
-ome/cadams,1,7611,96
-me/cbaxter,1,7615,96
-me/cjensen,1,7611,96
-ome/cklang,1,7615,96
-me/ckohler,1,7731,128
-e/cmargozz,1,7611,96
-e/cpitcher,1,7615,96
-e/cschroff,1,7611,96
-ome/cyoung,1,8880,576
-ome/daniel,1,7622,96


I am looking for out put like this:

Code:
-ommuniGate,1,7659,96
-ommuniGate,1,7717,96
-ommuniGate,1,261840,134880

-me/abhiram,1,7615,96
-me/abhiram,1,7615,96
-me/abhiram,1,7615,96

-me/ahonnik,1,7610,96
-me/ahonnik,1,7610,96
-me/ahonnik,1,7610,96

so on so for.....

How i can do this can someone help me please.

thanks,
-lalit
# 2  
Old 06-20-2008
Need Help

please someone help
thanks
# 3  
Old 06-21-2008
Try something like this:

Code:
awk -F "," '
{a[$1]=a[$1]"\n"$0}
END {
  for(i in a) {
    print a[i]
  }
}
' file1 file2 file3

Regards
# 4  
Old 06-21-2008
Code:
paste -d'\n' file1 file2 file3

# 5  
Old 06-21-2008
Hi.

Often we wish to see results in a sorted order. Here's an adaptation of a Franklin52 script preceded by a sort:
Code:
#!/bin/bash -

# @(#) s2       Demonstrate sort and break-text at field change.

echo
echo "(Versions displayed with local utility \"version\")"
version >/dev/null 2>&1 && version =o $(_eat $0 $1) sort edges
echo

FILES="data*"

sort -t, --key=1,1 $FILES |
./break-text.awk |
edges -c

exit 0

with break-text.awk as:
Code:
#!/usr/bin/env sh

# @(#) break-text.awk   Separate groups of line based on field.

# Use nawk or /usr/xpg4/bin/awk on Solaris.

# Based on:
# https://www.unix.com/shell-programming-scripting/
# 69362-how-print-empty-line-when-field-changed-2.html#post302206257
# by Franklin52.

FIELD=1

awk -v field="$FIELD" -F ',' '
NR == 1 {v=$field}
$field != v     {v=$field; print ""}
1
' $*

exit 0

Together producing:
Code:
% ./s2

(Versions displayed with local utility "version")
Linux 2.6.11-x1
GNU bash 2.05b.0
sort (coreutils) 5.2.1
edges (local) 307

     1  -/home/apps,1,323610,79168
     2  -/home/apps,1,323653,79168
     3  -/home/apps,1,328804,80384
     4
     5  -/home/atmf,0,7613,96
   ...
    51  -home/bbjen,1,7611,96
    52
    53  -home/blinn,0,1167752,412608
    54  -home/blinn,1,7620,96
    55  -home/blinn,1,7620,96
   ...
   103  -ome/daniel,1,7622,96
   104
   105  -ommuniGate,1,261840,134880
   106  -ommuniGate,1,7659,96
   107  -ommuniGate,1,7717,96

showing the first, middle, and last part of the output. (Utilities version and edges are local to my site, are not needed for execution, and are for demonstration purposes) ... cheers, drl
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Is there a way to handle commas inside the data when generating a csv file from shell script?

I am extracting data via sql query and some of the data has commas. Output File must be csv and I cannot update the data in the db (as it is used by other application). Example table FavoriteThings Person VARCHAR2(25), Favorite VARCHAR2(100) Sample Data Greta rain drop on... (12 Replies)
Discussion started by: patk625
12 Replies

2. Shell Programming and Scripting

Comparing to 3 data

# cat list.txt server1 server2 server3 server4 # data to be compared of. #dns address 1.1.1.1 2.2.2.2 3.3.3.3 #for i in `cat list.txt` do grep dns $ i done (1 Reply)
Discussion started by: invinzin21
1 Replies

3. Shell Programming and Scripting

Comparing Data file with Crtl file

Hi, I need to compare a file with its contents matching to that of another file(filename , received date and record count). Lets say has File A original data Ex - 1,abc,1234 2,bcd,4567 3,cde,8901 and File B has details of File A Ex- FILEA.TXT|06/17|2010|3 (filename)|(received... (18 Replies)
Discussion started by: Prashanth B
18 Replies

4. Shell Programming and Scripting

Creating loops inside a file and extracting and loading data

Help needed (1 Reply)
Discussion started by: Chand Shrestha
1 Replies

5. UNIX for Dummies Questions & Answers

Comparing lines of data

Total UNIX Rookie, but I'm learning. I have columns of integer data separated by spaces, and I'm using a Mac terminal. What I want to do: 1. Compare "line 1 column 2" (x) to "line 2 column 2" (y); is y-x>=100? 2. If yes, display difference and y's line number 3. If no, increment x and y by... (9 Replies)
Discussion started by: markymarkg123
9 Replies

6. Shell Programming and Scripting

Comparing the data in a 2 files

Hi Friends, I have a file 1 CREATE MULTISET TABLE TEYT_Q9_T.TEST ,NO FALLBACK , NO BEFORE JOURNAL, NO AFTER JOURNAL, CHECKSUM = DEFAULT, DEFAULT MERGEBLOCKRATIO ( XYZ DECIMAL(10,0), ABC VARCHAR(5) CHARACTER SET LATIN NOT CASESPECIFIC, PQR... (3 Replies)
Discussion started by: i150371485
3 Replies

7. Shell Programming and Scripting

Retrieve data from one file comparing the ID in the second file

Hi all, I have one file with IDs Q8NDM7 P0C1S8 Q8TF30 Q9BRP8 O00258 Q6AWC2 Q9ULE0 Q702N8 A4UGR9 Q13426 Q6P2D8 Q9ULM3 A8MXQ7 I want to compare ID file with another file which has complete information about these IDs and also about other IDs which are not in the above ID file. As... (10 Replies)
Discussion started by: kaav06
10 Replies

8. UNIX for Dummies Questions & Answers

How to get data only inside polygon created by points which is part of whole data from file?

hiii, Help me out..i have a huge set of data stored in a file.This file has has 2 columns which is latitude & longitude of a region. Now i have a program which asks for the number of points & based on this number it asks the user to enter that latitude & longitude values which are in the same... (7 Replies)
Discussion started by: reva
7 Replies

9. Shell Programming and Scripting

Comparing data in file with values in table

Hi, I want to calculate the number of pipe delimiters in a file for all lines seperately. For eg:i have a file Project.txt Mohit|chawla|123|678 File1|File2|345|767|678 And my file contains many lines like this it shd give me the output as 4 5 or give me the output for all the... (0 Replies)
Discussion started by: Mohit623
0 Replies

10. UNIX for Dummies Questions & Answers

Comparing data list...

I have a list of files that I want to compare to another list of files, how do I do that? The first list will be my known list and hard coded, for example: mylist="janfile.tar jarfile.jar jan.rpt.Z" etc. The second list will be found by doing an 'ls' piped to a file: ls > filelist.dat ... (4 Replies)
Discussion started by: giannicello
4 Replies
Login or Register to Ask a Question