Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - General
User Name
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.


  Search this Thread
Old 03-07-2013, 02:55 PM   #1
Registered: May 2011
Posts: 60

Rep: Reputation: 0
Cli command to search and print file content without printing searchword?

So here's what I'm trying to do - I want to create a script that searches the files in /usr/share/applications for terms like "Name", "Icon", "Cathegory" and "Exec" and I want the results (without the searchwords themselves) appear in a new file in this format: name icon category exec. So basically I want to create a script to automatically populate wmdrawer with contents from the .desktop files in /usr/share/applications. How can I best accomplish this without getting too complicated? I was thinking of using a combination of "grep" and "echo" commands but grep always outputs the searchwords too. Any ideas?
Old 03-07-2013, 04:27 PM   #2
Senior Member
Registered: Sep 2010
Location: Wales, UK
Distribution: Arch
Posts: 1,632
Blog Entries: 3

Rep: Reputation: 345Reputation: 345Reputation: 345Reputation: 345
Could you give a specific example? What about:

grep "foo" *.desktop | sed 's/foo//g'
Old 03-07-2013, 04:59 PM   #3
Senior Member
Registered: Jan 2011
Location: Youngstown, Ohio
Distribution: LM 17.1
Posts: 4,991
Blog Entries: 8

Rep: Reputation: 1210Reputation: 1210Reputation: 1210Reputation: 1210Reputation: 1210Reputation: 1210Reputation: 1210Reputation: 1210Reputation: 1210
grep -wE "Name|Exec|Icon|Categories" /usr/share/applications/*.desktop  | cut -d= -f2-

Last edited by Habitual; 03-07-2013 at 05:01 PM.


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
Printing large file using 'lpr -P' command causes a "pause" before and during print. JimWallace Linux - Kernel 3 01-17-2012 11:32 AM
[SOLVED] [Shell]Printing Content to File whocares357 Programming 5 10-23-2010 01:43 AM
[C] Can't print in screen the content of file netpumber Programming 7 03-20-2010 05:50 PM
how to search file's content with shell? arcow Linux - Software 2 02-08-2006 11:00 AM
C: How can i print out the content of a file in pages? akin81 Programming 1 03-25-2004 09:46 PM

All times are GMT -5. The time now is 01:10 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration