LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-12-2004, 06:22 AM   #1
night-blade1
LQ Newbie
 
Registered: Oct 2004
Posts: 1

Rep: Reputation: 0
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
 
Old 10-12-2004, 06:31 AM   #2
jkobrien
Member
 
Registered: Jun 2003
Location: Dublin, Ireland
Distribution: Slackware, LFS, Ubuntu, RedHat, Slamd64
Posts: 507

Rep: Reputation: 30
test = "Fedora" (tee-hee)

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

John
 
Old 10-12-2004, 07:01 AM   #3
theYinYeti
Senior Member
 
Registered: Jul 2004
Location: France
Distribution: Arch Linux
Posts: 1,897

Rep: Reputation: 63
test=`sed -n '/Fedora/ i Fedora' /etc/issue`

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

Yves.
 
Old 10-12-2004, 08:58 AM   #4
jkobrien
Member
 
Registered: Jun 2003
Location: Dublin, Ireland
Distribution: Slackware, LFS, Ubuntu, RedHat, Slamd64
Posts: 507

Rep: Reputation: 30
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
 
  


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
[c] searching for a word in a file saiz66 Programming 1 10-04-2004 09:46 PM
file+word problems warney_out Programming 3 09-02-2004 05:32 AM
MS Word file converter? pepelaz Programming 2 12-13-2003 08:37 AM
MS Word file converter? pepelaz Linux - Software 4 12-12-2003 03:48 PM
display full line instead of single word in for loop ken734 Linux - Newbie 3 08-15-2003 02:35 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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