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 03-08-2013, 05:16 PM   #1
DrVenom14
LQ Newbie
 
Registered: Mar 2013
Posts: 2

Rep: Reputation: Disabled
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!
 
Old 03-08-2013, 05:18 PM   #2
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,260

Rep: Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948
We don't do homework for you, but if you post your current code and where you're getting stuck we can offer advice.
 
Old 03-08-2013, 05:25 PM   #3
DrVenom14
LQ Newbie
 
Registered: Mar 2013
Posts: 2

Original Poster
Rep: Reputation: Disabled
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.
 
Old 03-08-2013, 05:33 PM   #4
Ser Olmy
Senior Member
 
Registered: Jan 2012
Distribution: Slackware
Posts: 2,404

Rep: Reputation: Disabled
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?

Last edited by Ser Olmy; 03-08-2013 at 05:34 PM.
 
Old 03-08-2013, 05:38 PM   #5
Habitual
LQ Addict
 
Registered: Jan 2011
Location: Youngstown, Ohio
Distribution: LM17.1/Xfce4.11.8
Posts: 7,190
Blog Entries: 10

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Quote:
Originally Posted by DrVenom14 View Post
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".
 
Old 03-08-2013, 07:40 PM   #6
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670
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.
 
Old 03-09-2013, 12:09 PM   #7
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
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/
 
  


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
Command line question ghostrider.002 Red Hat 1 05-19-2007 02:18 AM
Command line question shadoweyez Linux - Software 2 11-18-2005 07:28 PM
Command line question satimis Linux - General 14 06-20-2005 10:46 PM
command line question phonecian Linux - Software 2 10-09-2004 09:36 AM
command line question... warheros Linux - Newbie 12 06-25-2003 05:34 AM


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