The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Shell script: Remove blank lines gholdbhurg Shell Programming and Scripting 3 02-25-2009 02:33 PM
Command/Script to remove duplicate lines from the file? Rahulpict Shell Programming and Scripting 2 02-19-2009 10:13 PM
How to remove xml namespace from xml file using shell script? Gary1978 Shell Programming and Scripting 10 10-26-2008 09:32 PM
remove duplicates within a block in a file..help required nipun_garg Shell Programming and Scripting 2 07-23-2008 04:57 AM
Remove duplicates from File from specific location gopikgunda Shell Programming and Scripting 1 04-09-2008 02:16 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-25-2009
RichElks RichElks is offline
Registered User
  
 

Join Date: Feb 2009
Posts: 1
Shell script to remove duplicates lines in a file

Hi,

I am writing a shell script that needs to remove duplicate lines within a file by category.
example:
section a
a
c
b
a
section b
a
b
a
c

I need to remove the duplicates within th category with out removing the duplicates from the 2 different sections (one of the a's in section a, and one of the a's in section b).

I wanted to use uniq but i have to sort the file first...which takes the lines out of the sections they are supposed to be in and sorts the entire file which I don't want.....but I wouldn't mind sorting it by category if possible.

any help is appreciated.
  #2 (permalink)  
Old 02-25-2009
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
  
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,361
Code:
awk '/section/ { section = $2 } !x[section,$0]++' "$FILE"
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 12:34 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0