Sponsored Content
Top Forums Shell Programming and Scripting Remove duplicate lines after ignoring case and spaces between Post 302951719 by summer_cherry on Monday 10th of August 2015 03:47:45 AM
Old 08-10-2015
python

Code:
cache={}
with open("a.txt") as file:
	for line in file:
		line=line.replace("\n","")
		key=" ".join([i.lower() for i in filter(lambda x: x!="",line.split(" "))])
		if key not in cache:
			print(key)
			cache[key]=1

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Removing duplicate lines ignore case

hi, I have the following input in file: abc ab a AB b c a C B When I use uniq -u file,the out put file is: abc ab AB c v B C (17 Replies)
Discussion started by: hellsd
17 Replies

2. Shell Programming and Scripting

how to remove duplicate lines

I have following file content (3 fields each line): 23 888 10.0.0.1 dfh 787 10.0.0.2 dssf dgfas 10.0.0.3 dsgas dg 10.0.0.4 df dasa 10.0.0.5 df dag 10.0.0.5 dfd dfdas 10.0.0.5 dfd dfd 10.0.0.6 daf nfd 10.0.0.6 ... as can be seen, that the third field is ip address and sorted. but... (3 Replies)
Discussion started by: fredao
3 Replies

3. UNIX for Dummies Questions & Answers

Remove Duplicate lines from File

I have a log file "logreport" that contains several lines as seen below: 04:20:00 /usr/lib/snmp/snmpdx: Agent snmpd appeared dead but responded to ping 06:38:08 /usr/lib/snmp/snmpdx: Agent snmpd appeared dead but responded to ping 07:11:05 /usr/lib/snmp/snmpdx: Agent snmpd appeared dead but... (18 Replies)
Discussion started by: Nysif Steve
18 Replies

4. UNIX for Dummies Questions & Answers

deleteing duplicate lines sing uniq while ignoring a column

I have a data set that has 4 columns, I want to know if I can delete duplicate lines while ignoring one of the columns, for example 10 chr1 ASF 30 15 chr1 ASF 20 5 chr1 ASF 30 6 chr2 EBC 15 4 chr2 EBC 30 ... I want to know if I can delete duplicate lines while ignoring column 1, so the... (5 Replies)
Discussion started by: japaneseguitars
5 Replies

5. Shell Programming and Scripting

sed ignoring case for search but respecting case for subtitute

Hi I want to make string substitution ignoring case for search but respecting case for subtitute. Ex changing all occurences of "original" in a file to "substitute": original becomes substitute Origninal becomes Substitute ORIGINAL becomes SUBSTITUTE I know this a little special but it's not... (1 Reply)
Discussion started by: kmchen
1 Replies

6. Shell Programming and Scripting

Remove duplicate lines

Hi, I have a huge file which is about 50GB. There are many lines. The file format likes 21 rs885550 0 9887804 C C T C C C C C C C 21 rs210498 0 9928860 0 0 C C 0 0 0 0 0 0 21 rs303304 0 9941889 A A A A A A A A A A 22 rs303304 0 9941890 0 A A A A A A A A A The question is that there are a few... (4 Replies)
Discussion started by: zhshqzyc
4 Replies

7. UNIX for Dummies Questions & Answers

Remove Duplicate Lines

Hi I need this output. Thanks. Input: TAZ YET FOO FOO VAK TAZ BAR Output: YET VAK BAR (10 Replies)
Discussion started by: tara123
10 Replies

8. Shell Programming and Scripting

Count duplicate lines ignoring certain columns

I have this structure: col1 col2 col3 col4 col5 27 xxx 38 aaa ttt 2 xxx 38 aaa yyy 1 xxx 38 aaa yyy I need to collapse duplicate lines ignoring column 1 and add values of duplicate lines (col1) so it will look like this: col1 col2 col3 col4 col5 27 xxx 38 aaa ttt ... (3 Replies)
Discussion started by: coppuca
3 Replies

9. Shell Programming and Scripting

Remove lines containing 2 or more duplicate strings

Within my text file i have several thousand lines of text with some lines containing duplicate strings/words. I would like to entirely remove those lines which contain the duplicate strings. Eg; One and a Two Unix.com is the Best This as a Line Line Example duplicate sentence with the word... (22 Replies)
Discussion started by: martinsmith
22 Replies

10. Shell Programming and Scripting

How to remove duplicate lines?

Hi All, I am storing the result in the variable result_text using the below code. result_text=$(printf "$result_text\t\n$name") The result_text is having the below text. Which is having duplicate lines. file and time for the interval 03:30 - 03:45 file and time for the interval 03:30 - 03:45 ... (4 Replies)
Discussion started by: nalu
4 Replies
cache_set_and_retain(3) 				   BSD Library Functions Manual 				   cache_set_and_retain(3)

NAME
cache_set_and_retain, cache_get_and_retain, cache_release_value, cache_remove -- Routines used to manage cached values SYNOPSIS
#include <cache.h> int cache_set_and_retain(cache_t *cache, void *key, void *value, size_t cost); int cache_get_and_retain(cache_t *cache, void *key, void **value_out); int cache_release_value(cache_t *cache, void *value); int cache_remove(cache_t *cache, void *key); DESCRIPTION
These routines are used to manipulate values added to an in memory cache created by cache_create(3). cache_set_and_retain() Adds value with cost to cache and associates it with key. The caller retains a reference to value that will prevent value from being evicted from the cache until value is released in cache_release_value(). cache_get_and_retain() Fetches value for key from cache and places value in value_out. The caller retains a reference to value that will prevent value from being evicted from the cache until value is release in cache_release_value(). cache_release_value() Releases a reference on value back to cache so that value may be evicted. Signals that the client is not actively using value and will use cache_get_and_retain() before using again. cache_remove() Removes the value associated with key from cache. Note that if the value is referenced by a client, the value will not be finalized until the reference is released using cache_release_value(). RETURN VALUES
All functions return 0 for success and non-zero for failure. The value ENOENT (see errno.h) indicates that a key or value passed as an argu- ment does not exist in the cache. EINVAL is used for invalid arguments. EXAMPLE
The following example attempts to fetch a value from a cache using a key. If the value is not present in the cache then it is created and added to the cache. The value is then used and released back to the cache to allow the cache to evict it when needed. cache_t *mycache; cache_create("com.mycompany.mycache", &cache_attributes, &mycache); void *mykey = my_create_key(); void *myvalue = NULL; if (cache_get_and_retain(mycache, mykey, &myvalue) != 0) { myvalue = my_create_value_from_key(mykey); cache_set_and_retain(mycache, mykey, myvalue, 0); } my_use_value(value); cache_release_value(mycache, myvalue); SEE ALSO
cache(3) Darwin May 7, 2009 Darwin
All times are GMT -4. The time now is 03:16 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy