LinuxQuestions.org
Review your favorite Linux distribution.
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 06-16-2016, 10:46 AM   #1
hexle
LQ Newbie
 
Registered: Jun 2016
Posts: 12

Rep: Reputation: Disabled
sort


I cant understand the code below.I know what it does sort ,but when it is alone i mean it hasnt after something,i have no idea nor i find something in any book not even in google.Can someone give a good explanation to this line because i cant understand it.What i know to help cut is read the entrance and give the result to exit. After it refers to direcory to a file line 1 until 6 and read the archive etc passwd.Translate the empty.Thanks a lot

cut -d: -f1,6 /etc/passwd | tr : ' ' | sort
 
Old 06-16-2016, 10:52 AM   #2
hexle
LQ Newbie
 
Registered: Jun 2016
Posts: 12

Original Poster
Rep: Reputation: Disabled
help me please

explain this line please.
last searching the user that make the last mounth login.
egrep -v '^wtmp' = search starting with wtmp .
egrep -v '^$'=egrep search first starting with $ .I think refers to variable
cut -f1 -d ' ' = refers to file first line to directory and after empty
sort = make sort..
uniq -c=
sort -nr =

last |egrep -v '^wtmp' | egrep -v '^$'| cut -f1 -d' '| sort| uniq -c|sort -nr
 
Old 06-16-2016, 10:58 AM   #3
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,104

Rep: Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267
have you already seen the posting rules of LQ? http://www.catb.org/%7Eesr/faqs/smart-questions.html
have you checked man uniq (especially the flag -c)
have you checked man sort already?
 
Old 06-16-2016, 11:18 AM   #4
hexle
LQ Newbie
 
Registered: Jun 2016
Posts: 12

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by pan64 View Post
have you already seen the posting rules of LQ? http://www.catb.org/%7Eesr/faqs/smart-questions.html
have you checked man uniq (especially the flag -c)
have you checked man sort already?
i know what it does sort .but i dont know sort and after having something how it does this.I cant understand it
 
Old 06-16-2016, 12:05 PM   #5
Turbocapitalist
Member
 
Registered: Apr 2005
Distribution: Ubuntu, Devuan, OpenBSD
Posts: 956
Blog Entries: 3

Rep: Reputation: 391Reputation: 391Reputation: 391Reputation: 391
The output of the first program is fed into the next one using a pipe ( | ) and it goes from left to right through the chain. So at each step, you'll need to look up the man pages as suggested above earlier.

Code:
man uniq
man sort
 
Old 06-16-2016, 12:08 PM   #6
Habitual
LQ Addict
 
Registered: Jan 2011
Location: Youngstown, Ohio
Distribution: LM17.1/Xfce4.11.8
Posts: 7,159
Blog Entries: 10

Rep: Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968
http://wiki.linuxquestions.org/wiki/Uniq
 
Old 06-16-2016, 12:18 PM   #7
urbanwks
Member
 
Registered: Sep 2003
Distribution: Slackware64-Current, FreeBSD 11.0
Posts: 107

Rep: Reputation: 86
This appears to be more of this:

http://www.linuxquestions.org/questi...me-4175581794/
http://www.linuxquestions.org/questi...se-4175581964/

Here's an idea - rather than spin your wheels asking everyone to explain something someone else wrote for you that you can't understand, go back to the actual question, take it step by step, and learn about what you're supposed to do. Then do it. Ask questions only when you've exhausted all resources, and you have something specific to ask.

Or if you want to continue having someone else do your homework, go back to the person that originally wrote this for you. No one here is going to give you direct answers, only point you in a direction to LEARN about what you need to know (which they already have, in abundance). If you don't want to learn, then maybe you shouldn't have taken the course.
 
Old 06-16-2016, 12:29 PM   #8
ondoho
Senior Member
 
Registered: Dec 2013
Posts: 4,176

Rep: Reputation: 835Reputation: 835Reputation: 835Reputation: 835Reputation: 835Reputation: 835Reputation: 835
Quote:
Originally Posted by hexle View Post
last |egrep -v '^wtmp' | egrep -v '^$'| cut -f1 -d' '| sort| uniq -c|sort -nr
6 pipes! quite a monster.
i'm sure this could be coded nicer.

as was said before, look at the man pages of each command.

what i also like to do with these monsters:
i execute them once as is, then i delete everything until and including the last pipe, see what that gives me, and proceed so on until i get to the first command.
 
1 members found this post helpful.
Old 06-16-2016, 12:50 PM   #9
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,245

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
All of the above are correct, but not only do you need to look up the man for your new commands, but you really need to go and look at the man for cut as your very first example and explanation
are completely wrong.

I think the funny thing is that all the commands and files for your examples exist in all distributions so you could literally run each part of each command until you have the whole line and get
a very good understanding of exactly what the commands are doing.

As you seem to not understand what everyone is saying (maybe because English is not your first language), I'll break it down for you:

Before looking at either example, you will need to man bash and search for (using /) Pipelines, which will explain what the | symbol is doing.

First example:
1. man cut and specifically look at what the -d and -f options are for as your current understanding is wrong

2. Open the file /etc/passwd in an editor and look at the entries so you have a before comparison

3. Execute only the cut portion of the code and review the output and compare to what you saw above (or even better yet have the file open in an editor and then run command so you can see differences):
Code:
cut -d: -f1,6 /etc/passwd
4. man tr and get an understanding of SET1 and SET2. For your example SET1 is the colon ( and SET2 is a space

5. Execute up to tr command and compare to step 3:
Code:
cut -d: -f1,6 /etc/passwd | tr : ' '
6. man sort and read the description. You may also wish to google some examples

7. Execute the entire command and compare last output to that of step 5:
Code:
cut -d: -f1,6 /etc/passwd | tr : ' ' | sort
Next piece of code:

1. man last as your current understanding is incorrect

2. Execute last and inspect the output
Code:
last
3. man grep (this covers grep, egrep and fgrep) and specifically look at the -v option as your current understanding is wrong and is seriously point you in a bad direction for the results

4. Look up regular expressions as your current understanding of $ is wrong (here is a start and you will want to look up anchors)

5. Execute each egrep in turn to compare the output to step 2:
Code:
last | egrep -v '^wtmp'
Code:
last | egrep -v '^wtmp' | egrep -v '^$'
6. Execute up to first sort (one then the other and compare to step 5 output) as you have already learned about cut and sort in above example:
Code:
last | egrep -v '^wtmp' | egrep -v '^$' | cut -f1 -d' '
last | egrep -v '^wtmp' | egrep -v '^$' | cut -f1 -d' ' | sort
7. man uniq and review the information on the -c switch as well as the description

8. Execute up to uniq and review output compared to step 6:
Code:
last | egrep -v '^wtmp' | egrep -v '^$' | cut -f1 -d' ' | sort | uniq -c
9. Review the man page for sort and look at the specific switches -n and -r

10. Execute and compare to output in step 8:
Code:
last | egrep -v '^wtmp' | egrep -v '^$' | cut -f1 -d' ' | sort | uniq -c | sort -nr
In case you were wondering, this is how all the other users here have learned and as you will see this takes some time, which is why everyone is upset that you are not making any effort
when we all had to and you just want to get the benefit of our hard work.

Last edited by grail; 06-16-2016 at 12:52 PM.
 
1 members found this post helpful.
  


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
Is there a sort of 2nd SSH daemon server, sort of JAILKIT, in the debian repositories frenchn00b Debian 5 06-20-2010 05:03 AM
Can I use GNU sort to sort one field in order, another in reverse? zombieite Linux - Newbie 4 04-27-2009 01:23 AM
php sort help - sort numerical descending then by alphabetical? RavenLX Programming 3 03-11-2009 09:35 AM
selection sort compiles but does not sort the array as desired ganesha Programming 2 04-20-2008 08:44 AM
Is there a line limit with the sort utility? Trying to sort 130 million lines of text gruffy Linux - General 4 08-10-2006 09:40 PM


All times are GMT -5. The time now is 08:12 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