remove consecutive duplicate rows


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting remove consecutive duplicate rows
# 8  
Old 06-08-2011
"The answer is b, needs to appear only once in the output"

...
sorry you confuse me :
a
b
b
c
c
a
d
should appear
a
b
c
a
d
or should appear
a
a
d
?
# 9  
Old 06-08-2011
Quote:
Originally Posted by ctsgnb
"The answer is b, needs to appear only once in the output"

...
sorry you confuse me :
a
b
b
c
c
a
d
should appear
a
b
c
a
d
or should appear
a
a
d
?
And I'm going to keep confusing you, sorry I meant option a. It's been one of those days, since I'm trying to work on three different projects, one in python, one in c++, and one in bash.

Code:
a
a
b
c
c
d
e
e

should appear in the unique file as,
Code:
a
b
c
d
e

and also in the duplicate log as,
Code:
a
c
e

LMHmedchem
# 10  
Old 06-09-2011
Did you try what i suggested in my post #3:

Code:
awk '{sub(".*"$2,$2)}1' yourfile | uniq >output.txt

Code:
awk '{sub(".*"$2,$2)}1' yourfile | uniq -d >duplicate.txt

???

And check the content of the generated *.txt files
# 11  
Old 06-09-2011
Hope this help

Code:
 
awk 'v=$0;getline;{if(v=$0){print $0 > "dup.txt"}else{print v > "file.txt"}}'

# 12  
Old 06-09-2011
I haven't tried it but i suppose something like this would do the work as well :

Code:
awk '{p=c;c=$0}p{f=(p==c)?"dup.txt":"file.txt";print c > f}' inputfile

could be enforce a little (just in case p has the '0' value)
Code:
awk '{p=c;c=$0}length(p){f=(p==c)?"dup.txt":"file.txt";print c > f}' inputfile


Last edited by ctsgnb; 06-09-2011 at 07:07 AM..
# 13  
Old 06-09-2011
Yet another way of doing the same thing...
Code:
awk '{print $0 >> (x[$2]?"dups":"nodups");x[$2]=$0}' file

# 14  
Old 06-09-2011
Oooops i forgot something
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remove duplicate consecutive lines with specific string

Hello, I'm trying to remove the duplicate consecutive lines with specific string "WARNING". File.txt abc; WARNING 2345 WARNING 2345 WARNING 2345 WARNING 2345 WARNING 2345 bcd; abc; 123 123 123 WARNING 1234 WARNING 2345 WARNING 2345 efgh; (6 Replies)
Discussion started by: Mannu2525
6 Replies

2. Shell Programming and Scripting

Check/print missing number in a consecutive range and remove duplicate numbers

Hi, In an ideal scenario, I will have a listing of db transaction log that gets copied to a DR site and if I have them all, they will be numbered consecutively like below. 1_79811_01234567.arc 1_79812_01234567.arc 1_79813_01234567.arc 1_79814_01234567.arc 1_79815_01234567.arc... (3 Replies)
Discussion started by: newbie_01
3 Replies

3. Shell Programming and Scripting

Compute value from more than three consecutive rows

Hello all, I am working on a file like below: site Date time value1 value2 0023 2014-01-01 00:00 32.0 23.7 0023 2014-01-01 01:00 38.0 29.9 0023 2014-01-01 02:00 85.0 26.6 0023 2014-01-01 03:00 34.0 25.3 0023 2014-01-01 04:00 37.0 23.8 0023 2014-01-01 05:00 80.0 20.3 0023 2014-01-01 06:00... (16 Replies)
Discussion started by: kathy wang
16 Replies

4. Shell Programming and Scripting

Remove duplicate rows based on one column

Dear members, I need to filter a file based on the 8th column (that is id), and does not mather the other columns, because I want just one id (1 line of each id) and remove the duplicates lines based on this id (8th column), and does not matter wich duplicate will be removed. example of my file... (3 Replies)
Discussion started by: clarissab
3 Replies

5. UNIX for Dummies Questions & Answers

Remove duplicate rows when >10 based on single column value

Hello, I'm trying to delete duplicates when there are more than 10 duplicates, based on the value of the first column. e.g. a 1 a 2 a 3 b 1 c 1 gives b 1 c 1 but requires 11 duplicates before it deletes. Thanks for the help Video tutorial on how to use code tags in The UNIX... (11 Replies)
Discussion started by: informaticist
11 Replies

6. Shell Programming and Scripting

remove html tags,consecutive duplicate lines

I need help with a script that will remove all HTML tags from an HTML document and remove any consecutive duplicate lines, and save it as a text document. The user should have the option of including the name of an html file as an argument for the script, but if none is provided, then the script... (7 Replies)
Discussion started by: clicstic
7 Replies

7. Shell Programming and Scripting

To remove date and duplicate rows from a log file using unix commands

Hi, I have a log file having size of 48mb. For such a large log file. I want to get the message in a particular format which includes only unique error and exception messages. The following things to be done : 1) To remove all the date and time from the log file 2) To remove all the... (1 Reply)
Discussion started by: Pank10
1 Replies

8. Shell Programming and Scripting

awk script to remove duplicate rows in line

i have the long file more than one ns and www and mx in the line like . i need the first ns record and first www and first mx from line . the records are seperated with tthe ; i am try ing in awk scripting not getiing the solution. ... (4 Replies)
Discussion started by: kiranmosarla
4 Replies

9. UNIX for Dummies Questions & Answers

Remove duplicate rows of a file based on a value of a column

Hi, I am processing a file and would like to delete duplicate records as indicated by one of its column. e.g. COL1 COL2 COL3 A 1234 1234 B 3k32 2322 C Xk32 TTT A NEW XX22 B 3k32 ... (7 Replies)
Discussion started by: risk_sly
7 Replies

10. Shell Programming and Scripting

How to capture 2 consecutive rows when a condition is true ?

Hi All, i have an input below. As long as "x= 1" , i would want to capture 2 lines using sed or awk for eg : 0001 x= 1 $---------------------------------..-.--.. 0001 tt= 137 171 423 1682 2826 0 Pls help. Thanks in advance. Note that the number of lines in each block do... (37 Replies)
Discussion started by: Raynon
37 Replies
Login or Register to Ask a Question