LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   help... get single word from file (https://www.linuxquestions.org/questions/programming-9/help-get-single-word-from-file-241656/)

night-blade1 10-12-2004 06:22 AM

help... get single word from file
 
hey

I'm doing a little test.

i want to find single word within a file and put it in a variable.
but i dont know how.
Heres an example of what i want to do.

test=`grep Fedora /etc/issue`

but this gets the hole line.

echo $test #Fedora Core release 2 (tettnang)

how do i get Fedora only?

thanks

jkobrien 10-12-2004 06:31 AM

test = "Fedora" (tee-hee)

Otherwise, grep's -o switch will return only the matching part of a line, try that.

John

theYinYeti 10-12-2004 07:01 AM

test=`sed -n '/Fedora/ i Fedora' /etc/issue`

I don't really get what you want, though...

Yves.

jkobrien 10-12-2004 08:58 AM

I guess that "Fedora" is only an example, and that he's searching with a regexp or with a list of search terms in a file, so he needs to know which exact search term produced the hit.

John


All times are GMT -5. The time now is 08:21 AM.