|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Compare 2 files
Hi, I want to compare file1 (file1_column 1) with file2 (file2_column1), if the file2_column1 match in file1 (file1_column 1) then print that line from file2 to new file (file3).
second, I want only unique values(I can use (file3_column_1) in file3 or create new file (file 4). File1: ID111 Test1 IN111 test2 IP112 test5 NC113 test9 File2: NC113 test9 NC113 test9 IN111 test2 PC123 test22 Output: NC113 test9 IN111 test2 Thanks. |
|
#2
|
|||
|
|||
|
One way using awk
Code:
awk ' FILENAME=="file1" { arr[$1]=$0 }
FILENAME=="file2" { if(arr($1]) print arr[$1]}
' file1 file2 | sort -u > file3
|
|
#3
|
|||
|
|||
|
Quote:
read man sort && comm
__________________
working on Solaris[5-9], preferred languages french and C. |
|
#4
|
|||
|
|||
|
Hi Jim, Thanks for you help.
I run the script but getting an error. here is my scripts. #!/bin/ksh EXPORT_HOME=/export/home/Test/scripts/ EXPORT_HOME_SCRIPTS=$EXPORT_HOME/Yash cd $EXPORT_HOME_SCRIPTS FILE1=user_id_list; export FILE1 FILE2=/logs/active_id.log; export FILE2 awk -F 'FILENAME=="FILE1" { arr[$1]=$0 } FILENAME=="FILE2" { if(arr($1]) print arr[$1]} 'FILE1 FILE2 | so rt -u} > file3 exit 0 error message. awk: syntax error near line 1 awk: illegal statement near line 1 awk: syntax error near line 1 is there something am i missing here? |
|
#5
|
||||
|
||||
|
What about:
Code:
for line in `more file1`; do grep $line file2 | sort -u >> file3; done
__________________
UNIX shells are so cool! etienne:~ > %blow fg: %blow: no such job There are 10 kind of people: - those who know binary - those who don't. |
|
#6
|
|||
|
|||
|
a) sort your files
b) read man pages of comm c) you got it |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > Compare 2 files |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|