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
Deleting multiple lines from file shekhar_v4 Shell Programming and Scripting 9 03-16-2009 08:38 AM
deleting lines after pattern using sed larne Shell Programming and Scripting 2 10-13-2008 12:54 PM
Checking for a file in file pattern before deleting it dsrookie UNIX for Dummies Questions & Answers 1 05-09-2008 04:29 PM
prom in deleting a pattern suvendu4urs Shell Programming and Scripting 18 04-10-2008 06:36 AM
deleting multiple records from a huge file at one time dsravan Shell Programming and Scripting 5 02-06-2008 11:17 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 04-21-2009
lassimanji lassimanji is offline
Registered User
  
 

Join Date: Apr 2009
Posts: 58
deleting multiple accourances of a pattern from a file

I have a .sh file with the following contents:
a
b
c
a
a
b
d
c

i want to delete the multiple occurances and keep one. say there are 3 a's in the file. I want to delete 2 of them and just keep 1 occurance.
  #2 (permalink)  
Old 04-21-2009
devtakh devtakh is offline
Registered User
  
 

Join Date: Oct 2007
Location: Bangalore
Posts: 514
sort -u a.sh


cheers,
Devaraj Takhellambam
  #3 (permalink)  
Old 04-21-2009
lassimanji lassimanji is offline
Registered User
  
 

Join Date: Apr 2009
Posts: 58
thanks
  #4 (permalink)  
Old 04-21-2009
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,119
Code:
nawk '!a[$0]++' a.sh
  #5 (permalink)  
Old 04-21-2009
lassimanji lassimanji is offline
Registered User
  
 

Join Date: Apr 2009
Posts: 58
if the file is like

a
c
b
check interface a
check interface b

and i want to perform the same action for both a and check interface a , thus i need to keep only one of them in my file. how do i do a sort in that case
  #6 (permalink)  
Old 04-21-2009
devtakh devtakh is offline
Registered User
  
 

Join Date: Oct 2007
Location: Bangalore
Posts: 514
u need to understand the patter that precedes the text and remove it.

sed 's/check interface //g' dupsed | sort -u

cheers,
Devaraj Takhellambam
  #7 (permalink)  
Old 04-21-2009
lassimanji lassimanji is offline
Registered User
  
 

Join Date: Apr 2009
Posts: 58
can u expalin alitlle about dupsed. what does it do
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 10:47 AM.


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