Specialty Forums
Security and Virus
General Hardware
CPUs/Overclocking
Networking
Digital Photo/Video
Office Software
PC Gaming
Console Gaming
Programming
Database
Web Development
Digital Home

General Forums
Windows XP
Windows Vista
Windows 95/98
Windows Me
Windows NT
Windows 2000
Win Server 2008
Win Server 2003
Windows 3.1
Linux
PDAs
BeOS
Novell Netware
OpenVMS
Solaris
Disk Op. System
Unix
Mac
OS/2

Drivers
Driver Scan
Driver Forum

Software
Automatic Updates

BIOS Updates

My Computing.Net

Solution Center

Free IT eBook

Howtos

Site Search

Message Find

RSS Feeds

Install Guides

Data Recovery

About

Home
Reply to Message Icon Go to Main Page Icon

to remove duplicate lines from file

Original Message
Name: Palsanthi
Date: July 8, 2005 at 00:29:55 Pacific
Subject: to remove duplicate lines from file
OS: unix
CPU/Ram: 1.8 GHZ / 256 MB
Comment:
hai,
i want to remove duplicate lines from any part of the file...uniq command is used to remove only the adjacent duplicate lines...if we use sort command with -u option it removes duplicate lines from any part of the file,but the file is sorted...i dont want the file to be sorted,but i want to remove duplicate lines from any part of the file.... this is my problem...if anybody knows answer for this please reply....


Report Offensive Message For Removal


Response Number 1
Name: Jim Boothe
Date: July 8, 2005 at 06:45:18 Pacific
Subject: to remove duplicate lines from file
Reply: (edit)
If your file is not extremely large, the awk script below should work.

awk '{
if ($0 in stored_lines)
   x=1
else
   print
   stored_lines[$0]=1
}' filein > fileout


Report Offensive Follow Up For Removal

Response Number 2
Name: Palsanthi
Date: July 10, 2005 at 21:59:20 Pacific
Subject: to remove duplicate lines from file
Reply: (edit)
Reply:

hai Jim,

thanx a lot for ur response....the sript u gave is working...i got wat i want...
thank u very much...


Report Offensive Follow Up For Removal

Response Number 3
Name: VKJAIN
Date: July 11, 2005 at 06:32:26 Pacific
Subject: to remove duplicate lines from file
Reply: (edit)
My requirement is little different, actually I have 2 files, one of the file has 800 line another has 50. No I wanted to check with respect to first file if there are any duplicate lines in 2nd file. And if it is present then the output file should remove that line from the 800 lines. It should not add any lines of file2. Only it should check with respect to 1st file.


Report Offensive Follow Up For Removal

Response Number 4
Name: Jim Boothe
Date: July 11, 2005 at 07:34:30 Pacific
Subject: to remove duplicate lines from file
Reply: (edit)
awk 'BEGIN{
while ((getline < "file50") > 0)
   list50[$1] = 1}
!list50[$1] {print}' file800 > file800new


Report Offensive Follow Up For Removal

Response Number 5
Name: VKJAIN
Date: July 12, 2005 at 06:49:55 Pacific
Subject: to remove duplicate lines from file
Reply: (edit)
Whn i use this script it says

> awk 'BEGIN
Unmatched '.


Report Offensive Follow Up For Removal


Response Number 6
Name: Jim Boothe
Date: July 12, 2005 at 07:22:38 Pacific
Subject: to remove duplicate lines from file
Reply: (edit)
Some platforms require each end-of-line to be escaped with a backslash when a quoted string overflows to multiple lines. Try this:

awk 'BEGIN{ \
while ((getline < "file50") > 0) \
   list50[$1] = 1} \
!list50[$1] {print}' file800 > file800new


Report Offensive Follow Up For Removal

Response Number 7
Name: VKJAIN
Date: July 12, 2005 at 07:23:19 Pacific
Subject: to remove duplicate lines from file
Reply: (edit)

It worked well after going into bash mode.

Thanks a lot Jim


Report Offensive Follow Up For Removal



Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: to remove duplicate lines from file

Comments:

 
  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 


Data Recovery Software




Batch File- Current Date in Excel

how to setup call of duty to joytok

WindowsME / HotMail Problem

Corrupt memory

Convert fat32 to Ntfs


The information on Computing.Net is the opinions of its users. Such opinions may not be accurate and they are to be used at your own risk. Computing.Net cannot verify the validity of the statements made on this site. Computing.Net and Computing.Net, LLC hereby disclaim all responsibility and liability for the content of Computing.Net and its accuracy.
PLEASE READ THE FULL DISCLAIMER AND LEGAL TERMS BY CLICKING HERE

All content ©1996-2007 Computing.Net, LLC