LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   sort (https://www.linuxquestions.org/questions/linux-newbie-8/sort-4175582426/)

hexle 06-16-2016 09:46 AM

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

hexle 06-16-2016 09:52 AM

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

pan64 06-16-2016 09:58 AM

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?

hexle 06-16-2016 10:18 AM

Quote:

Originally Posted by pan64 (Post 5561891)
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

Turbocapitalist 06-16-2016 11:05 AM

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


Habitual 06-16-2016 11:08 AM

http://wiki.linuxquestions.org/wiki/Uniq

urbanwks 06-16-2016 11:18 AM

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.

ondoho 06-16-2016 11:29 AM

Quote:

Originally Posted by hexle (Post 5561886)
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.

grail 06-16-2016 11:50 AM

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.


All times are GMT -5. The time now is 11:43 AM.