Linux command
Hi guys,
For my homework I have to explain the following command: cut –f 5 –d: /etc/passwd | grep ‘^K’ | wc –l Would you you please help me out? Thank you! |
LQ is not here to answer homework questions for you.
How about you offer "your" explanation? People may then offer any corrections or statements about varied interpretations. And have you run this command sequence? Have you tried any part of it? Have you looked up what cut, pipe, and grep all do? |
Yes I did, in fact I am an old man trying to learn, I am not trying just go by.
My understanding is the command will first search for delimeter ":" and then split the contents into fields, in this case are 5 fields. Fields 1 to 4 contents will be then deleted so it will display the contents from fifth field by end of line of each line. Then this output will be sent as input to grep. After that I am stuck! I don;t know how to finish it. Thank you for your help! |
Well look at just the grep command, it is searching for ^K within the string extracted by the cut command. The wc portion gives you a count of newlines, thus how many valid search results were detected because they will have been delimited by newlines.
A further suggestion is in your terminal to first type "set -xv" to enable verbose and debug in the shell. This is a per session thing, so once you exit that terminal, new terminals will not have those settings, unless your environment is set up that way, but that is non-typical. What does it do? An example of a simple grep: Code:
set -xv |
LINK here is some info on grep, and it has an example using the carat "^"
|
I suggest you run the following commands, start with the basics and then build up to see what each addition changes. Only move to the next command once you understand what's going on with the current one.
Code:
cat /etc/passwd |
Thank you so much rtmistler for your detailed explanation! Also thank you dab1414 for the link. suicidaleggroll, thank you for your suggestion. As a new in to this Linux world, that is the best way to do it. The problem is that I want to learn to fast....
Thank you again! |
Quote:
Best of luck with the studies and your efforts. :) |
I now completely understand rtmistler. I am not a very experienced user when using forums plus as I said before English is my second language, so in many cases my words are npot the meaning I am looking for. Thank you again for your help! I am looking forward of participating in this great forum!
|
Quote:
man grep man wc check out: https://www.youtube.com/watch?v=nLa6jAbULe8 http://how-to.linuxcareer.com/learni...x-commands-cut |
All times are GMT -5. The time now is 08:09 AM. |