LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Command Line Question (https://www.linuxquestions.org/questions/linux-newbie-8/command-line-question-4175453317/)

DrVenom14 03-08-2013 04:16 PM

Command Line Question
 
I am new student taking a class in Linux. I am having trouble with a couple of questions currently.

1) I have to run a command that shows all of /etc/passwd starting with line 20.

2) I made a file that contains several different numbers. In this file there are two '42' entries. I need help with the command that would combine those two '42' entries into one.

Thanks for your help!

suicidaleggroll 03-08-2013 04:18 PM

We don't do homework for you, but if you post your current code and where you're getting stuck we can offer advice.

DrVenom14 03-08-2013 04:25 PM

I'm not looking for anyone to do my homework for me. My point is this: I understand the significance in understanding what I am doing and not looking for an easy grade. I am taking on IT as a career and cheating isn't going to help me. I need help and thought this was the best forum for it.

To answer your question, there really isn't any code. The questions are all something I can type into the command line to make it do something. This is a beginning Unix/Linux class. I can't find the answer to my two questions online or in my book.

With the second question, it specifically asks for a command that consolidates two '42' entries within a file into one entry.

Again, I appreciate the help.

Ser Olmy 03-08-2013 04:33 PM

In the first scenario, you need to pipe the /etc/passwd file through a command that strips the first 19 lines from the output. There are numerous ways to accomplish this, but you may want to take a close look at the tail command.

As for the second scenario, you would need to seek out the two "42" entries and then somehow combine them. By "entry", do you mean an entire line containing the number 42? How is the output supposed to look?

Edit: What is the name of the book you're using?

Habitual 03-08-2013 04:38 PM

Quote:

Originally Posted by DrVenom14 (Post 4907643)
there really isn't any code. The questions are all something I can type into the command line to make it do something. This is a beginning Unix/Linux class. I can't find the answer to my two questions online or in my book.

I am certain the instruction or labwork would have covered these tasks, or at the very least suggested what the right tool for the job is supposed to be.

pseudo-code perhaps? you know,

if
this is true,
do this.
else
do that
fi

Every shell script starts off with a bang, that, at least is better than "isn't any code".

jschiwal 03-08-2013 06:40 PM

For the first problem you can use `sed' with a range selection. Use the -n option and the print command, or select what you don't want to see and use the delete command.
You will find plenty of examples using used on the web.

I don't follow what you are asking about 42. It's supposed to be The Answer to the Ultimate Question of Life, the Universe, and Everything. If they ask about 420, start worrying.

David the H. 03-09-2013 11:09 AM

I imagine that what you really need is a guide to where to look for information.

Start by looking at at "info coreutils" for a rundown of the basic maintenance-level programs available. These, plus grep, sed awk, and built-in shell features, will cover the majority of your shell-processing needs.

And here's my list of useful online references:

bash:
http://mywiki.wooledge.org/BashGuide
http://wiki.bash-hackers.org/start
http://www.linuxcommand.org/index.php
http://wiki.bash-hackers.org/scripting/newbie_traps
http://mywiki.wooledge.org/BashPitfalls
http://mywiki.wooledge.org/BashFAQ
http://tldp.org/LDP/Bash-Beginners-G...tml/index.html
http://www.tldp.org/LDP/abs/html/index.html
http://www.gnu.org/software/bash/manual/bashref.html
http://ss64.com/bash/

sed:
http://www.grymoire.com/Unix/Sed.html
http://sed.sourceforge.net/grabbag/
http://sed.sourceforge.net/sedfaq.html
http://sed.sourceforge.net/sed1line.txt
http://www.catonmat.net/series/sed-one-liners-explained

awk:
http://www.grymoire.com/Unix/Awk.html
http://www.gnu.org/software/gawk/man...ode/index.html
http://www.pement.org/awk/awk1line.txt
http://www.catonmat.net/series/awk-one-liners-explained

find:
http://mywiki.wooledge.org/UsingFind
http://www.grymoire.com/Unix/Find.html

ed:
http://wiki.bash-hackers.org/howto/edit-ed
http://snap.nlc.dcccd.edu/learn/nlc/ed.html
(also read the info page)

regular expressions:
http://mywiki.wooledge.org/RegularExpression
http://www.grymoire.com/Unix/Regular.html
http://www.regular-expressions.info/


All times are GMT -5. The time now is 12:09 PM.