To display unique lines in a Program


 
Thread Tools Search this Thread
Top Forums Programming To display unique lines in a Program
# 1  
Old 07-04-2011
To display unique lines in a Program

I am new to C programming. I have been trying to display unique lines in a file from past two days. The problem is here,

I have a file whose contents are,
Code:
ras.beamtele.net
ras.beamtele.net
ras.beamtele.net
ras.beamtele.net
ras.beamtele.net
ras.beamtele.net
ras.beamtele.net
ras.beamtele.net
ras.beamtele.net
crawl-66-249-72-97.googlebot.com
27.61.242.247
27.61.242.247
27.61.242.247
27.61.242.247
27.61.242.247
1.23.209.154
27.61.242.247
1.23.209.154
1.23.209.154
1.23.209.154

and i need to display all unique lines. And the output should be,
Code:
ras.beamtele.net
crawl-66-249-72-97.googlebot.com
27.61.242.247
1.23.209.154.

Please help me how to do it using C language.
Thanks in advance.

Last edited by Franklin52; 07-04-2011 at 09:23 AM.. Reason: Please use code tags for code and data samples, thank you
# 2  
Old 07-04-2011
Look at the source code for the uniq utility.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Count of unique lines in field 4

When I use the below awk to count the unique lines in $4 for the input it seems to work. The answer is 3 because $4 is only unique 3 times in all the entries. However, when I use the same on actual data I get 56,536 and I know the answer should be 56,548. My question is there a better way to... (8 Replies)
Discussion started by: cmccabe
8 Replies

2. UNIX for Dummies Questions & Answers

Print unique lines without sort or unique

I would like to print unique lines without sort or unique. Unfortunately the server I am working on does not have sort or unique. I have not been able to contact the administrator of the server to ask him to add it for several weeks. (7 Replies)
Discussion started by: cokedude
7 Replies

3. Shell Programming and Scripting

Transpose lines from individual blocks to unique lines

Hello to all, happy new year 2013! May somebody could help me, is about a very similar problem to the problem I've posted here where the member rdrtx1 and bipinajith helped me a lot. https://www.unix.com/shell-programming-scripting/211147-map-values-blocks-single-line-2.html It is very... (3 Replies)
Discussion started by: Ophiuchus
3 Replies

4. UNIX for Dummies Questions & Answers

getting unique lines from 2 files

hi i have used comm -13 <(sort 1.txt) <(sort 2.txt) option to get the unique lines that are present in file 2 but not in file 1. but some how i am getting the entire file 2. i would expect few but not all uncommon lines fro my dat. is there anything wrong with the way i used the command? my... (1 Reply)
Discussion started by: anurupa777
1 Replies

5. Shell Programming and Scripting

display unique words.

I am having a file with duplicate words how can I eliminate them ant,bat bat,cat cat a.txt | grep -bat | awk '{print $1}' expecting o/p as ant,bat,cat How can I display the output as ant,bat,cat in a single line and no duplicates exists. (2 Replies)
Discussion started by: shikshavarma
2 Replies

6. UNIX for Advanced & Expert Users

In a huge file, Delete duplicate lines leaving unique lines

Hi All, I have a very huge file (4GB) which has duplicate lines. I want to delete duplicate lines leaving unique lines. Sort, uniq, awk '!x++' are not working as its running out of buffer space. I dont know if this works : I want to read each line of the File in a For Loop, and want to... (16 Replies)
Discussion started by: krishnix
16 Replies

7. Homework & Coursework Questions

Filtering Unique Lines

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: The uniq command excludes consecutive duplicate lines. It has a -c option to display a count of the number... (1 Reply)
Discussion started by: billydeanmak
1 Replies

8. Shell Programming and Scripting

Remove All Lines Between Two Unique Lines

Hi all! Im wondering if its possible to remove all lines between two lines. Im working with a document like this: data1 data2 <Remove> data3 data4 </Remove> data5 data6 I need it to end up like this if that possible: data1 data2 data5 data6 There are multiple instances of... (2 Replies)
Discussion started by: Grizzly
2 Replies

9. Shell Programming and Scripting

how many unique lines in a file

I have a file, test.txt with approx 12,000 lines. Each line is a single word that looks like a hex address. There are many repeats. Over half of the lines are the same. I want to count how many UNIQUE lines there are. #>more test.txt 0x123456 0x56AF23 0x99ABC1 0x123456 0x123456 0x99ABC1... (3 Replies)
Discussion started by: ajp7701
3 Replies

10. Shell Programming and Scripting

display unique number

Hi, how i can display all the unique number from my random number script below; #!/usr/bin/perl use strict; my @alphanum = ( 'A' .. 'Z', 'a' .. 'z', 0 .. 9); my $random = join('', map($alphanum,(1..5))); print "$random\n"; Thank You. (1 Reply)
Discussion started by: malaysoul
1 Replies
Login or Register to Ask a Question