![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
| using sed to get rid of duplicated columns... | fedora | Shell Programming and Scripting | 5 | 11-28-2008 10:45 AM |
| Can root ID be duplicated | lorcan | UNIX for Advanced & Expert Users | 6 | 06-16-2007 12:06 AM |
| grep and delete ONE only | happyv | Shell Programming and Scripting | 10 | 01-16-2007 10:02 AM |
| checking jump sequence number (part2) | happyv | Shell Programming and Scripting | 3 | 10-19-2006 07:03 AM |
| copy syntax part2 | tomapam | UNIX for Dummies Questions & Answers | 3 | 07-02-2002 12:14 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
grep and delete 2nd duplicated of txt... -part2
Hi,
I find out one problem is...the main point is we must delete 2nd duplicated of word in txt file. For example apple orange pink green orange yellow orange red output should be: apple orange pink green yellow orange red #For the above, check all words in txt file and delete the 2nd duplicated of word (and MUST not use sort to do, because of the order should not be changed - only delete the duplicated). Due to the file may be over 10000 words, it is very difficult for me to check..by manually..... any small script can help? |
|
|||||
|
What's wrong with the solution in this thread?
And your definition of duplicated is a bit confusing. To delete duplicate entries means that except the first entry, all other entries of that word/phrase will be deleted. Another question. Is this any form of school work/home work? |
|
||||
|
count=0
cat {1} | while read line do count=`echo "${count} + 1" | bc` cc=`head -${count} ${1} |grep -c ${line}` if [ ${cc} -eq 2 ] then : else echo ${line} fi done Would this work ? I have not tested it but it should work. save it as a file , give it execute permission and then use it as "script filename". All the best. It's a simple logic but i think that would work for you. Regds, Kaps |
|
||||
|
Quote:
|
|
||||
|
Quote:
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|