Register a domain and help support LQ
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


Search this Thread
Old 09-03-2009, 08:16 AM   #1
LQ Newbie
Registered: Sep 2009
Posts: 1

Rep: Reputation: 0
Question 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.


Last edited by $Arsh; 09-04-2009 at 01:04 AM.
Old 09-03-2009, 08:37 AM   #2
Registered: Jan 2005
Location: Midwest USA, Central Illinois
Distribution: SlackwareŽ
Posts: 11,573
Blog Entries: 7

Rep: Reputation: 1560Reputation: 1560Reputation: 1560Reputation: 1560Reputation: 1560Reputation: 1560Reputation: 1560Reputation: 1560Reputation: 1560Reputation: 1560Reputation: 1560

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.
Old 09-03-2009, 08:38 AM   #3
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959
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.

Last edited by colucix; 09-03-2009 at 08:41 AM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Comparing two files to get matched contents in another file using shell script pooppp Linux - Networking 3 08-05-2008 01:11 AM
simple php script to add line/file to text file dnoy Programming 1 05-21-2008 06:08 PM
Random file lines directed to a new file. In script an error. In command line no err leventis Programming 1 09-28-2006 08:16 AM
problem deleting file using solaris command line. szehanz Solaris / OpenSolaris 2 03-22-2005 08:52 PM
deleting a file via comman line PionexUser Linux - General 2 09-17-2003 01:27 AM

All times are GMT -5. The time now is 08:03 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration