LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Command Help (https://www.linuxquestions.org/questions/linux-general-1/command-help-175814/)

IRIGHTI 04-29-2004 01:05 AM

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.

320mb 04-29-2004 01:19 AM

how bout' "read"

http://www.ss64.com/bash/read.html

AskMe 04-29-2004 01:53 AM

Try these!!!
 
Give a try following commands
cat
more
less

TheRealDeal 04-29-2004 01:58 AM

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 :)

kvedaa 04-29-2004 10:07 AM

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.

IRIGHTI 04-29-2004 11:24 AM

Hey thanks alot kvedaa, that worked great!

Thanks to everyone else for giving it a go as well.

TheRealDeal 04-29-2004 05:32 PM

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


All times are GMT -5. The time now is 06:17 AM.