Need unix commands to delete records from one file if the same record present in another file...


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need unix commands to delete records from one file if the same record present in another file...
# 1  
Old 05-07-2012
Need unix commands to delete records from one file if the same record present in another file...

Need unix commands to delete records from one file if the same record present in another file...



just like join ... if the record present in both files.. delete from first file or delete the particular record and write the unmatched records to new file..

tried with grep and while loop... but no luck... can anyone help on this?






Last edited by msathees; 05-07-2012 at 07:21 AM.. Reason: changing the subject
# 2  
Old 05-07-2012
show, what you tried so far ?

please post correct heading while posting a thread

The UNIX and Linux Forums - Forum Rules

(11) Post questions with descriptive subjects. For example, do not post questions with subjects like "Help Me!", "Urgent!!" or "Doubt". Post subjects like "Execution Problems with Cron" or "Help with Backup Shell Script".
# 3  
Old 05-07-2012
tried with the below codes for getting the unmatched records... but the issue here is while loop will return unmatched records for every loop ... I need only a single output which it should contain only unmatched records

Code:
while read a ; do
  grep -v "^${a}$" a.file;
done < b.file

a.file --target file

b.file--- required records to be matched

Last edited by Scrutinizer; 05-07-2012 at 07:28 AM.. Reason: code tags
# 4  
Old 05-07-2012
Code:
 
cp a.file a.file.orig
while read a ; do
  grep -v "^${a}$" a.file > /tmp/tmp.out
  mv /tmp/tmp.out a.file
done < b.file

# 5  
Old 05-07-2012
got the expected result....very thanks kamaraj Smilie
# 6  
Old 05-07-2012
How about:
Code:
grep -vxFf b.file a.file

# 7  
Old 05-08-2012
working fine....thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Need help to delete special characters exists only at the end of the each record in UNIX file?

Hi, I have a file in unix with 15 columns.It consists special characters(#,$,^M,@,*,% etc)at the end of the each record.I want to remove these special characters.I used the following: Sed -e 's/ /g;s/ */ /g' . But It is removing special characters exists everywhere in the file(begining,middle... (24 Replies)
Discussion started by: rakeshp
24 Replies

2. Shell Programming and Scripting

Total record count of all the file present in a directory

Hi All , We need one help on the below requirement.We have multiple pipe delimited .txt file(around 100 .txt files) present on one directory.We need the total record count of all the files present in that directory without header.File format as below : ... (8 Replies)
Discussion started by: STCET22
8 Replies

3. Shell Programming and Scripting

Split a large file in n records and skip a particular record

Hello All, I have a large file, more than 50,000 lines, and I want to split it in even 5000 records. Which I can do using sed '1d;$d;' <filename> | awk 'NR%5000==1{x="F"++i;}{print > x}'Now I need to add one more condition that is not to break the file at 5000th record if the 5000th record... (20 Replies)
Discussion started by: ibmtech
20 Replies

4. Shell Programming and Scripting

Delete records in mysql database where record is less than today

Guys, I need help. I need to create a script to delete records in mysql database where record is 2 days old. Thanks. (1 Reply)
Discussion started by: jasperux
1 Replies

5. Shell Programming and Scripting

Delete a pattern present in file 2 from file 1 if found in file 1.

I have two files File1 ==== 1|2000-00-00|2010-02-02|| 2| 00:00:00|2012-02-24|| 3|2000-00-00|2011-02-02|| File2 ==== 2000-00-00 00:00:00 I want the delete the patterns which are found in file 2 from file 1, Expected output: File1 ==== (5 Replies)
Discussion started by: machomaddy
5 Replies

6. UNIX for Advanced & Expert Users

query display number lines or records present in file only numeric value -without filename

Hi all Thanks in advance........... Please help me for this issue............ I have a file it has 11 records . I used the command like .... >$ wc -l file 11 file I'm getting output like 11 file (no.of records along with filename) here my requirement is, I want to display only... (3 Replies)
Discussion started by: ksrivani
3 Replies

7. Shell Programming and Scripting

converting all records of a file in to one record

I have a file temp.dat. The contents of this file is as follows abcdefgh abcdefgh abcdefgh abcdefgh abcdefgh abcdefgh The multiple records in this file needs to be converted in to a single record. abcdefgh abcdefgh abcdefgh abcdefgh abcdefgh abcdefgh (2 Replies)
Discussion started by: rsriramiyer
2 Replies

8. Shell Programming and Scripting

Delete Strings that are present in another file

HI, if a String is present in file1.txt, i want to delete that String from file2.txt. How can i do this?? I am sure that the file1.txt is a subset of file2.txt. (2 Replies)
Discussion started by: jathin12
2 Replies

9. Shell Programming and Scripting

To find the count of records from tables present inside a file.

hi gurus, I am having a file containing a list of tables.i want to find the count of records inside thes tables. for this i have to connect into database and i have to put the count for all the tables inside another file i used the following loop once all the tablenames are inside the file. ... (1 Reply)
Discussion started by: navojit dutta
1 Replies

10. Shell Programming and Scripting

how to delete record in file data with index in another file?

I want to deal with several data, i.e., data.*.txt with following structure MSG|20010102|123 125 4562 409|SEND MSG|20010102|120 230|SEND MSG|20010102|120 204 5071|SEND MSG|20010103|2 11 1098 9810|SEND ...... index file index.txt is 11 201 298 100 ...... What I want to do is: 1)... (0 Replies)
Discussion started by: zhynxn
0 Replies
Login or Register to Ask a Question