LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 12-13-2005, 03:11 AM   #1
spx2
Member
 
Registered: Dec 2005
Distribution: debian
Posts: 160

Rep: Reputation: 30
script output


locate gaim | grep desktop
gives me output :
/usr/share/apps/kappfinder/apps/Internet/gaim.desktop
i want to read that file on my console
i try
more | locate gaim | grep desktop
nothing happens
but if i do
more /usr/share/apps/kappfinder/apps/Internet/gaim.desktop
the file is being outputed
what operators and how do i do this in a single line ?
 
Old 12-13-2005, 03:12 AM   #2
Poetics
Senior Member
 
Registered: Jun 2003
Location: California
Distribution: Slackware
Posts: 1,181

Rep: Reputation: 49
iirc, "locate gaim | grep desktop | more" would work

Edit: In English, "find 'Gaim' files. Show me the listings with 'desktop' in the name. Print them to the screen."

And remember, 'less' is more.

Last edited by Poetics; 12-13-2005 at 03:14 AM.
 
Old 12-13-2005, 03:13 AM   #3
spx2
Member
 
Registered: Dec 2005
Distribution: debian
Posts: 160

Original Poster
Rep: Reputation: 30
i just tried it

[stef@localhost stef]$ locate gaim | grep desktop | more
/usr/share/apps/kappfinder/apps/Internet/gaim.desktop
[stef@localhost stef]$
 
Old 12-13-2005, 03:15 AM   #4
Poetics
Senior Member
 
Registered: Jun 2003
Location: California
Distribution: Slackware
Posts: 1,181

Rep: Reputation: 49
pardon me, I forgot an operator... I'll leave that to a guru to answer
 
Old 12-13-2005, 03:27 AM   #5
spx2
Member
 
Registered: Dec 2005
Distribution: debian
Posts: 160

Original Poster
Rep: Reputation: 30
i dont really understand...
 
Old 12-13-2005, 03:53 AM   #6
Bebo
Member
 
Registered: Jul 2003
Location: Göteborg
Distribution: Arch Linux (current)
Posts: 553

Rep: Reputation: 30
There are (at least) two ways of doing it:

Code:
cat $(locate gaim | grep desktop)
which is equivalent to

Code:
cat `locate gaim | grep desktop`
and

Code:
locate gaim | grep desktop | xargs cat
The output can then be piped (|) to more (or less), or you can exchange cat to what you want.
 
Old 12-13-2005, 04:12 AM   #7
spx2
Member
 
Registered: Dec 2005
Distribution: debian
Posts: 160

Original Poster
Rep: Reputation: 30
please explain the syntax fot he `` signs
also for the $() you used there wich i dont know what it is
but it sure works
also what is xargs
and why are you using cat instead of more ?
ive tried it with "more" too and it works
thanks allot but please give answers to above questions so i
can understand better
 
Old 12-13-2005, 04:41 AM   #8
Bebo
Member
 
Registered: Jul 2003
Location: Göteborg
Distribution: Arch Linux (current)
Posts: 553

Rep: Reputation: 30
Well, I used cat instead of more to show the principle. It's for you to write your script so that it suits you

The $(stuff) and `stuff` notations are, as I said, equivalent; choose one that suits you. When you use this, stuff is executed first, and the output is replacing this on the command line. So when you do

Code:
more $(locate gaim | grep desktop)
the stuff inside the $() is executed first, and gives you the result "/usr/share/apps/kappfinder/apps/Internet/gaim.desktop". This result replaces the $(stuff) on the command line and what more sees is

Code:
more /usr/share/apps/kappfinder/apps/Internet/gaim.desktop

xargs is a bit more involved, but to quote the man page it is used to "build and execute command lines from standard input". Anyway, when you do stuff | xargs command, the result of the command stuff will be used as arguments to command.


(BTW, when I say stuff I refer to a general command line, not just one single command.)


For more info on bash scripting see the Advanced Bash-Scripting Guide - it will (almost) never fail you
 
Old 12-13-2005, 04:55 AM   #9
spx2
Member
 
Registered: Dec 2005
Distribution: debian
Posts: 160

Original Poster
Rep: Reputation: 30
is this http://linuxcommand.org good ?
 
Old 12-13-2005, 04:55 AM   #10
spx2
Member
 
Registered: Dec 2005
Distribution: debian
Posts: 160

Original Poster
Rep: Reputation: 30
also why isnt Bebo 's command working ?
 
Old 12-13-2005, 05:32 AM   #11
Bebo
Member
 
Registered: Jul 2003
Location: Göteborg
Distribution: Arch Linux (current)
Posts: 553

Rep: Reputation: 30
Well, linuxcommand.org seems good too. There are numerous of these kind of sites, and every one of them may tell you something that the others don't

What about what command? Which isn't working?
 
Old 12-13-2005, 05:35 AM   #12
spx2
Member
 
Registered: Dec 2005
Distribution: debian
Posts: 160

Original Poster
Rep: Reputation: 30
why is locate gaim | grep desktop | more
not working ?
 
Old 12-13-2005, 08:44 AM   #13
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
It works fine--it just isn't the right command.....

"locate gaim" finds your gaim file --the output is the path to the file---not the file
"grep desktop" extracts the line in the output of locate which contains the word "desktop"
"more" pages the output one screen at a time---in your case, there is only one line, so more is superflous.
Nowhere did you issue a command to actually read the file named "gaim.desktop""

Time to read some manuals....I would start with "Bash guide for beginners" by Machtelt Garrels. It's on TLDP

Also highly recommended is a good book on shell scripting.

Last edited by pixellany; 12-13-2005 at 08:45 AM.
 
  


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
how to silence script output (so I don't get so many cron logs)? BrianK Programming 2 03-01-2005 04:53 PM
python read output from seperate script? bendeco13 Programming 1 02-01-2005 10:38 PM
shell script output redirection goral.j Programming 3 01-27-2005 05:34 AM
help with init script output ierickson Linux - General 0 05-07-2004 12:05 PM
script is capturing output.... wedgeworth Linux - Software 7 10-20-2003 05:11 PM


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