LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 09-03-2009, 07:16 AM   #1
$Arsh
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

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

Last edited by $Arsh; 09-04-2009 at 12:04 AM.
 
Old 09-03-2009, 07:37 AM   #2
onebuck
Moderator
 
Registered: Jan 2005
Location: Central Florida 20 minutes from Disney World
Distribution: SlackwareŽ
Posts: 13,925
Blog Entries: 44

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

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

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


Reply



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 12:11 AM
simple php script to add line/file to text file dnoy Programming 1 05-21-2008 05: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 07:16 AM
problem deleting file using solaris command line. szehanz Solaris / OpenSolaris 2 03-22-2005 07:52 PM
deleting a file via comman line PionexUser Linux - General 2 09-17-2003 12:27 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:15 AM.

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