LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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, 12: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, 12:41 PM   #2
jdkaye
LQ Guru
 
Registered: Dec 2008
Location: Westgate-on-Sea, Kent, UK
Distribution: Debian Testing Amd64
Posts: 5,465

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, 12: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, 01: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, 01:09 PM   #5
hortageno
Member
 
Registered: Aug 2015
Distribution: Ubuntu 22.04 LTS
Posts: 240

Rep: Reputation: 67
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, 01: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, 01: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, 01: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, 06:51 PM   #9
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
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, 10:02 PM   #10
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

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


Reply



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 12:26 PM
Microsoft Word - Automatic Selection Word Count? NotAComputerGuy General 8 10-29-2012 05:18 AM
variable length string using GD (word wrap, carriage return, word/character count)? frieza Programming 1 02-14-2009 05:21 PM
how to count each word in file using php? andie87 Linux - Software 2 11-14-2008 02: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 09:08 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:22 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
Open Source Consulting | Domain Registration