-   Linux - Newbie (
-   -   script for deleting matched line of a file from another file (

$Arsh 09-03-2009 07:16 AM

script for deleting matched line of a file from another file
hi everybody
i have two text file named 1.txt & 2.txt
1.txt contains 5 laks of mobile number.
2.txt has 60 laks of mob no.
situation is that i want to find and delete numbers in 2.txt which already in 1.txt
so can any body provide me any perl or bash script or any other way to get
the work done

i tried the following
#! /bin/bash

for NAME in $(cat one.txt)
sed -ie "\|^$NAME\$|d" two.txt
echo "***DONE***"
it works well with smaller file but it take very very long time even processing 10 thousand numbers.
plz ur support urgently required.


onebuck 09-03-2009 07:37 AM


Welcome to LQ!

Now that we are all aware of your 'needs'. What are your 'deeds'?

Seriously it would be easier if you provide us with what you have attempted to solve your task? Then we can aid you.

Especially if this is homework then aid is what we should give you since you would be the one getting grades on the project. :)

colucix 09-03-2009 07:38 AM

A method using grep:

grep -v -f 1.txt 2.txt > 3.txt
Edit (after reading post by onebuck): I did not thought about homework question when posting the code above. My fault.

All times are GMT -5. The time now is 11:52 AM.