LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   script for deleting matched line of a file from another file (https://www.linuxquestions.org/questions/linux-newbie-8/script-for-deleting-matched-line-of-a-file-from-another-file-752367/)

$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

IFS=$'\n'
for NAME in $(cat one.txt)
do
sed -ie "\|^$NAME\$|d" two.txt
done
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.


thanks

onebuck 09-03-2009 07:37 AM

Hi,

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:
Code:

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 10:38 AM.