LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-21-2015, 01:23 PM   #1
fng77
LQ Newbie
 
Registered: Oct 2015
Posts: 14

Rep: Reputation: Disabled
Get info from a file uniq word count


I have a testfile containing say

cat
house
car
car
tits
shop

Im looking for a command how can tell me how many unique lines there are in this text file? with a number. In this case 5.

I have tried sort, cat ,uniq, wc -l with all there gears. Bu I am doing something wrong?

Can anyone explain what to me?

Thaks
 
Old 10-21-2015, 01:41 PM   #2
jdkaye
LQ Guru
 
Registered: Dec 2008
Location: Westgate-on-Sea, Kent, UK
Distribution: Debian Testing Amd64
Posts: 5,464

Rep: Reputation: Disabled
Is this homework?
Have a look at
Code:
man uniq
That will provide you with most of the solution.
jdk
 
Old 10-21-2015, 01:53 PM   #3
fng77
LQ Newbie
 
Registered: Oct 2015
Posts: 14

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by jdkaye View Post
Is this homework?
Have a look at
Code:
man uniq
That will provide you with most of the solution.
jdk
Yes it is a old one, that I cant seem to get right. I have read the man and uniq -u seems good. And I have read all internet and done almost everything with the file. Can do just about everything but get the number of uniq lines?
 
Old 10-21-2015, 02:00 PM   #4
fng77
LQ Newbie
 
Registered: Oct 2015
Posts: 14

Original Poster
Rep: Reputation: Disabled
and if I write -u -c I get the uniqe lines with a number before. but I just want the number.
 
Old 10-21-2015, 02:09 PM   #5
hortageno
Member
 
Registered: Aug 2015
Distribution: Ubuntu 14.04 LTS
Posts: 230

Rep: Reputation: 65
Quote:
Originally Posted by fng77 View Post
and if I write -u -c I get the uniqe lines with a number before. but I just want the number.
man wc
 
Old 10-21-2015, 02:24 PM   #6
fng77
LQ Newbie
 
Registered: Oct 2015
Posts: 14

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by hortageno View Post
man wc
Ok, I can count the words in the file with wc -w and get a number. Good start! But then I only want the uniq once. Can I pipe wc to uniq or vice vers. I dont know wich order to do it or the way either for that case?

But to get the number of lines is a very good start!
 
Old 10-21-2015, 02:31 PM   #7
fng77
LQ Newbie
 
Registered: Oct 2015
Posts: 14

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by fng77 View Post
Ok, I can count the words in the file with wc -w and get a number. Good start! But then I only want the uniq once. Can I pipe wc to uniq or vice vers. I dont know wich order to do it or the way either for that case?

But to get the number of lines is a very good start!

I get so mad with this shit! Ive been doing almost everything with a good result, but gets totaly stuck in this first course. I just cant seem to handle piping and stuff like that..
 
Old 10-21-2015, 02:49 PM   #8
fng77
LQ Newbie
 
Registered: Oct 2015
Posts: 14

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by fng77 View Post
I get so mad with this shit! Ive been doing almost everything with a good result, but gets totaly stuck in this first course. I just cant seem to handle piping and stuff like that..

Thank you dear god! I had a error in my test file that was driving me crazy!

Then I used the command: sort -u xxxx.txt | wc -l


Thank you!!!!!!!!!!!
 
Old 10-21-2015, 07:51 PM   #9
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
Piping is definitely a core skill that you need to absorb.
Well worth playing around with it for a while until you've got it.

Glad you found your soln in the end.

When really stuck, assume nothing / check everything... we've all been there
 
Old 10-21-2015, 11:02 PM   #10
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,243

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
Please mark as SOLVED once you have a solution.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Extract info and find/count strings from blocks inside text file Alkass Programming 6 01-24-2015 01:26 PM
Microsoft Word - Automatic Selection Word Count? NotAComputerGuy General 8 10-29-2012 06:18 AM
variable length string using GD (word wrap, carriage return, word/character count)? frieza Programming 1 02-14-2009 06:21 PM
how to count each word in file using php? andie87 Linux - Software 2 11-14-2008 03:30 PM
how to delete last number/word of a file and incude file count at the end of the chennaiguy Linux - Newbie 2 02-18-2008 10:08 PM


All times are GMT -5. The time now is 10:40 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration