print unmatched data from 2 files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting print unmatched data from 2 files
# 1  
Old 04-20-2011
print unmatched data from 2 files

Hi,

i need help to extract unmatched data from 2 files. for instance, the input file like below:

file1.txt
Code:
ID   hit      addhit
123  sp        q9876  
656  sp        q5641
332  sp        d1211
248  sp        f5642

file2.txt
Code:
ID      Num     def        activity
123     447     trial      norm
332     478     trial      un

and output should be the unmatched record which is:-

file3.txt
Code:
656  q5641
248  f5642

i have thousands data like this that i need to work on. i did try some awk script but it just combine both data from both files. any kind help would be appreciated..thanks..
# 2  
Old 04-20-2011
Code:
nawk 'FNR=NR {f2[$1];next} !($1 in f2){print $1, $3}' file2.txt file1.txt > file3.txt

# 3  
Old 04-20-2011
Hi vgersh99,

thanks for your prompt response...

tried your script but it just gave me blank file.. Smilie
# 4  
Old 04-20-2011
Quote:
Originally Posted by redse171
Hi vgersh99,

thanks for your prompt response...

tried your script but it just gave me blank file.. Smilie
sorry, fat fingers.....
Code:
nawk 'FNR==NR {f2[$1];next} !($1 in f2){print $1, $3}' file2.txt file1.txt > file3.txt

This User Gave Thanks to vgersh99 For This Post:
# 5  
Old 04-20-2011
Hi vgersh99,

It works now..thanks so much.. Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

In PErl script: need to read the data one file and generate multiple files based on the data

We have the data looks like below in a log file. I want to generat files based on the string between two hash(#) symbol like below Source: #ext1#test1.tale2 drop #ext1#test11.tale21 drop #ext1#test123.tale21 drop #ext2#test1.tale21 drop #ext2#test12.tale21 drop #ext3#test11.tale21 drop... (5 Replies)
Discussion started by: Sanjeev G
5 Replies

2. Shell Programming and Scripting

<< unmatched error

Hi all, I want to call a plsql package that does not return any value. I am using the following script to do so: sqlplus $UserNamePwd <<EOF set head off begin test_pkg.procedure('$DebugFlag'); end; exit EOF if then log_message "procedure failed." exit 1 fi exit $? I... (2 Replies)
Discussion started by: reshma15193
2 Replies

3. Shell Programming and Scripting

How to compare 2 files and create a result file with unmatched lines from first file.?

HI, I have 2 text files. file1 and file2. file1.txt (There are no duplicates in this file) 1234 3232 4343 3435 6564 6767 1213 file2.txt 1234,wq,wewe,qwqw 1234,as,dfdf,dfdf 4343,asas,sdds,dsds 6767,asas,fdfd,fdffd I need to search each number in file1.txt in file2.txt's 1st... (6 Replies)
Discussion started by: Little
6 Replies

4. Shell Programming and Scripting

Unmatched <<

Hi, I am running sinple ksh script . From some reason it failed on the following error: ./ogg_status.sh: syntax error at line 16 : `<<' unmatched Please advise. #!/usr/bin/ksh export ORACLE_HOME=/software/oracle/DB10gR2 export LD_LIBRARY_PATH=/software/oracle/DB10gR2/lib:/usr/lib... (4 Replies)
Discussion started by: yoavbe
4 Replies

5. Shell Programming and Scripting

`for' unmatched

:b:Hi guys, I am getting this error in this piece of code, Any help will be appreciate rypidoc.shl: syntax error at line 79 : `for' unmatched ##Determine if there is a file to process ls 3526*.dat > /dev/null 2>&1 if then exit fi for i in 3526*.dat do # Capture just the file... (2 Replies)
Discussion started by: rechever
2 Replies

6. Shell Programming and Scripting

done' unexpected and do' unmatched

Good morning, I have been teaching myself shell scripting and seem to be stuck here. I am sure I am just blind and not seeing it so I thought maybe some fresh eyes would help. With the script below I keep getting.... "syntax error at line 248 : `done' unexpected" I am not seeing why this... (6 Replies)
Discussion started by: LRoberts
6 Replies

7. Shell Programming and Scripting

reading two files, comparing, printing when unmatched value is seen

Hello, I have two files: file1 1 2 3 4 5 file2 "a","b",,,,,"c","1",..... "s","d",,,,,"s","1",..... "a","c",,,,,"d","1",.... "f","v",,,,,,"f","2",..... etc I have to read "1" from file1 and grab all records in file2 (say column 6 in file2 is "1") until the column changes its value (... (6 Replies)
Discussion started by: i.scientist
6 Replies

8. Shell Programming and Scripting

else unmatched

I'm getting an else unmatched error on the script below.. For info : SYDB is the database name entered as a param on the command line. #Check the DB name HBDB=`sql $SYDB <<_END_ | grep '^|' | grep -v dbase | sed 's/|//g' | sed 's/ //g' set autocommit on; \p\g set lockmode... (7 Replies)
Discussion started by: b.hamilton
7 Replies

9. UNIX for Dummies Questions & Answers

Logging HP-UX print data

Hi, Can anyone advise if there is a utility or a known script that I can use to log all print activity on our unix box. We are running HP-UX version B.11.00. The type of thing I would want to record is: user, printer, pages, time Any help you may offer will be gratefully received. ... (0 Replies)
Discussion started by: pmaths
0 Replies

10. Shell Programming and Scripting

Delete unmatched data

Hi, I try to write script to compare 2 data file (list of numbers) which after that I want to delete unmatched numbers and create new file for matched numbers. Can anybody to help me? (5 Replies)
Discussion started by: nazri76
5 Replies
Login or Register to Ask a Question