LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 04-29-2004, 01:05 AM   #1
IRIGHTI
Member
 
Registered: Oct 2003
Distribution: Slackware64 13.1 x86_64, Ubuntu 10.04 x86_64
Posts: 121

Rep: Reputation: 15
Command Help


I need a command that will ouput a certain line in a text file.

Not a line with known string aka grep.

I just want it to spit out say line 56 of the file.

Any ideas? I've googled, searched here, etc. and can't find a thing.
 
Old 04-29-2004, 01:19 AM   #2
320mb
Senior Member
 
Registered: Nov 2002
Location: pikes peak
Distribution: Slackware, LFS
Posts: 2,577

Rep: Reputation: 48
how bout' "read"

http://www.ss64.com/bash/read.html
 
Old 04-29-2004, 01:53 AM   #3
AskMe
Member
 
Registered: Jul 2003
Posts: 123

Rep: Reputation: 15
Try these!!!

Give a try following commands
cat
more
less
 
Old 04-29-2004, 01:58 AM   #4
TheRealDeal
Member
 
Registered: Jun 2003
Location: Central Coast, NSW, Australia
Distribution: Gentoo
Posts: 438

Rep: Reputation: 30
Hi.

There might be an easier way to do this. But this works for me.

This is to display the 8th line of my /etc/passwd file for example

cat -n /etc/passwd | grep 8


In your case you could do cat -n /your/file.txt | grep 56

Again, there is probably an easier way to do it, but I've always used this because I've never found another way

cat -n that will output and number each line, grep grabs what ever you enter after it. So it is basically numbering the output lines (not changing the file at all) and then showing the whole line you need.

Obviously just ignore the number it outputs for you.

>Craig
 
Old 04-29-2004, 10:07 AM   #5
kvedaa
Member
 
Registered: Mar 2004
Location: Virginia
Distribution: PacketProtector
Posts: 331

Rep: Reputation: 30
I like the workaround that "TheRealDeal" has proposed. But one concern that I have is if the file that you are attempting to grep through is a file that has a lot of numbers in it, you may well get a lot of information that you do not want.

Another option that you may want to try (I admit it is abit of a kludge, but it seems to work).

To display the 10th line of the /etc/host file:

tail +10 /etc/hosts | head -1

With this method you should be able to avoid false positives.
 
Old 04-29-2004, 11:24 AM   #6
IRIGHTI
Member
 
Registered: Oct 2003
Distribution: Slackware64 13.1 x86_64, Ubuntu 10.04 x86_64
Posts: 121

Original Poster
Rep: Reputation: 15
Hey thanks alot kvedaa, that worked great!

Thanks to everyone else for giving it a go as well.
 
Old 04-29-2004, 05:32 PM   #7
TheRealDeal
Member
 
Registered: Jun 2003
Location: Central Coast, NSW, Australia
Distribution: Gentoo
Posts: 438

Rep: Reputation: 30
Nice one kvedaa, I like it!! I hadn't thought about the file having numbers in it
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Is there a single command to list all hardware installed (command line)? davee Linux - Hardware 6 02-28-2009 07:19 PM
Require Linux/Perl equivalent command for windows Command alix123 Programming 7 08-19-2005 02:23 AM
Key stroke/command to shut down x and go into the command prompt screen? Fear58 Linux - General 1 07-14-2004 07:14 PM
Command to display whole filestructure hierarchy f/ command line? mjewell Linux - Newbie 10 01-19-2004 10:48 AM
Where is Command line utility for Cups and command tutorial mossy Linux - Software 8 01-16-2004 12:24 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 04:41 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
Open Source Consulting | Domain Registration