LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
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 05-20-2016, 02:01 PM   #1
torito
LQ Newbie
 
Registered: May 2016
Posts: 23

Rep: Reputation: Disabled
Thumbs up 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!
 
Old 05-20-2016, 02:06 PM   #2
rtmistler
Moderator
 
Registered: Mar 2011
Location: Sutton, MA. USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu
Posts: 5,119
Blog Entries: 10

Rep: Reputation: 1815Reputation: 1815Reputation: 1815Reputation: 1815Reputation: 1815Reputation: 1815Reputation: 1815Reputation: 1815Reputation: 1815Reputation: 1815Reputation: 1815
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?
 
1 members found this post helpful.
Old 05-20-2016, 02:24 PM   #3
torito
LQ Newbie
 
Registered: May 2016
Posts: 23

Original Poster
Rep: Reputation: Disabled
Unhappy

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!
 
Old 05-20-2016, 02:40 PM   #4
rtmistler
Moderator
 
Registered: Mar 2011
Location: Sutton, MA. USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu
Posts: 5,119
Blog Entries: 10

Rep: Reputation: 1815Reputation: 1815Reputation: 1815Reputation: 1815Reputation: 1815Reputation: 1815Reputation: 1815Reputation: 1815Reputation: 1815Reputation: 1815Reputation: 1815
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
grep 123 1.txt | wc -l
+ grep 123 1.txt
+ wc -l
1
This shows the FLOW of that command string, and will do the same for your command sequence.
 
Old 05-20-2016, 02:41 PM   #5
dab1414
Member
 
Registered: May 2011
Location: OK, USA
Distribution: Slackware 14.1_64
Posts: 70

Rep: Reputation: 50
LINK here is some info on grep, and it has an example using the carat "^"
 
Old 05-20-2016, 02:45 PM   #6
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,454

Rep: Reputation: 2052Reputation: 2052Reputation: 2052Reputation: 2052Reputation: 2052Reputation: 2052Reputation: 2052Reputation: 2052Reputation: 2052Reputation: 2052Reputation: 2052
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
cut -f 5 -d: /etc/passwd
cut -f 5 -d: /etc/passwd | grep '^K'
cut -f 5 -d: /etc/passwd | grep '^K' | wc -l
 
Old 05-20-2016, 02:46 PM   #7
torito
LQ Newbie
 
Registered: May 2016
Posts: 23

Original Poster
Rep: Reputation: Disabled
Thumbs up

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!

Last edited by torito; 05-20-2016 at 02:47 PM.
 
Old 05-20-2016, 03:03 PM   #8
rtmistler
Moderator
 
Registered: Mar 2011
Location: Sutton, MA. USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu
Posts: 5,119
Blog Entries: 10

Rep: Reputation: 1815Reputation: 1815Reputation: 1815Reputation: 1815Reputation: 1815Reputation: 1815Reputation: 1815Reputation: 1815Reputation: 1815Reputation: 1815Reputation: 1815
Quote:
Originally Posted by torito View Post
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!
We get that, but as you can see, you're going to get better results when you show you efforts. Saying the keyword "homework" may be a mistake given how you described in your follow up. Instead say, "Hey, I'm trying to self learn, and this is what I'm looking at ..." and then do try to include some details on your efforts. Believe me, you'll get far more respectful and helpful answers. Also be aware that some answers may not show up so very fast. Long, long ago I asked a doozy. I asked it fairly detailed, just no one had any answers. I sort of self-solved it in another manner and literally months later someone offered thoughts. It was at that point where I learned to follow-up and update my original question as Solved and also to include my solution on the matter. It helps.

Best of luck with the studies and your efforts.
 
Old 05-20-2016, 03:15 PM   #9
torito
LQ Newbie
 
Registered: May 2016
Posts: 23

Original Poster
Rep: Reputation: Disabled
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!
 
Old 05-21-2016, 02:21 AM   #10
JJJCR
Senior Member
 
Registered: Apr 2010
Posts: 1,205

Rep: Reputation: 197Reputation: 197
Question

Quote:
Originally Posted by torito View Post
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!
man cut

man grep

man wc

check out:
https://www.youtube.com/watch?v=nLa6jAbULe8
http://how-to.linuxcareer.com/learni...x-commands-cut
 
  


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
Any Linux command output to delimited format. Script should work for any command. torrelm@hotmail.com Linux - Newbie 9 09-04-2014 08:54 AM
LXer: How to access Linux command cheat sheets from the command line LXer Syndicated Linux News 0 07-28-2014 08:30 AM
URGENT! Is there any command to get a history command lines and time in SUSE Linux.? igsoper Linux - Software 5 06-25-2009 02:14 AM
LXer: The Linux Command Shell For Beginners: Fear Not The Command Line! LXer Syndicated Linux News 0 12-22-2008 06:30 PM
Translating windows pscp command to linux scp command help robward Linux - General 2 01-17-2008 06:02 AM


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