![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| need some help..Comparison | bluesilo | Shell Programming and Scripting | 0 | 02-23-2008 04:43 PM |
| Comparison of 2 files in UNIX | Dana Evans | UNIX for Dummies Questions & Answers | 32 | 11-21-2007 07:05 AM |
| String Comparison between two files using awk | rudoraj | Shell Programming and Scripting | 7 | 07-25-2006 12:04 PM |
| dir comparison help | ghazi | Shell Programming and Scripting | 5 | 12-20-2004 05:54 PM |
| comparison | cnf | Filesystems, Disks and Memory | 2 | 05-14-2002 02:52 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Hi,
I have two files file1 and file2 delimited by semicolon, And I want to compare column 2 and column3 of file1 to column3 and column 4 in file2. file1 -------- abc;cef;155.67;143_34; def;fgh;146.55;123.3; frg;hff;134.67;; yyy;fgh;134.78;35_45; file 2 --------- abc;cef;155.09;; abc;cef;155.67;143_34; asd;;;123; def;fgh;145.6;123.3; def;fgh;146.55;123.3; frg;hff;134.67;; Successfile1 ------------ abc;cef;155.67;143_34; def;fgh;146.55;123.3; Failfile1 ----------- frg;hff;134.67;; yyy;fgh;134.78;35_45; Can anyone help me with a script. |
|
||||
|
Hi Jerome
First of all wht is see is col2 of file 1 is text & col3 of file2 is number, so how u r going to compare? but still you can use somewhat this way #!/usr/bin/ksh cut -d";" -f2 file1 >> tmpf2.txt echo cut -d";" -f3 file2 >> tmpf3.txt diff tmpf2.txt tmpf3.txt cut -d";" -f3 file1 >> tmpf3.txt echo cut -d";" -f4 file2 >> tmpf4.txt diff tmpf3.txt tmpf4.txt rm tmpf[0-9].txt ![]() |
|
||||
|
Problem.
Hi Grial,
Thanks for your prompt and quick response. The script works for comparing two cols i.e., col 3 and col4 of two files. If i try to try to compare only col3 of two files, I am getting redundant records. Eg: My File1 consists of 100 records and file2 consists of 238 records.If i try to compare,file1 and file2 I got 116 records as my o/p in the console.Can u suggest me,how to rectify this. |
|
|||||
|
Again, I don't know if I've understood. Do you mean you could have duplicate records on file2? Or, Do you want only the first ocurrence? If this is teh case, try: Code:
#!/bin/bash
comp1=($(cat text1.txt | cut -d\; -f 3,4))
comp2=($(cat text2.txt | cut -d\; -f 3,4))
for str in ${comp1[*]}; do
i=0
while (( $i < ${#comp2[*]} )); do
if [[ $str = ${comp2[i]} ]]; then
cat text1.txt | grep $str
break
fi
(( i += 1 ))
done
done
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|