LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
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.

Notices

Reply
 
LinkBack Search this Thread
Old 03-07-2013, 01:55 PM   #1
linuxlicious
Member
 
Registered: May 2011
Posts: 48

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, 03:27 PM   #2
Snark1994
Senior Member
 
Registered: Sep 2010
Location: Wales, UK
Distribution: Arch
Posts: 1,630
Blog Entries: 3

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

Code:
grep "foo" *.desktop | sed 's/foo//g'
?
 
Old 03-07-2013, 03:59 PM   #3
Habitual
Senior Member
 
Registered: Jan 2011
Distribution: Slack14_64_Multilib
Posts: 2,726
Blog Entries: 3

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

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


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 On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are 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 10:32 AM
[SOLVED] [Shell]Printing Content to File whocares357 Programming 5 10-23-2010 12:43 AM
[C] Can't print in screen the content of file netpumber Programming 7 03-20-2010 04:50 PM
how to search file's content with shell? arcow Linux - Software 2 02-08-2006 10:00 AM
C: How can i print out the content of a file in pages? akin81 Programming 1 03-25-2004 08:46 PM


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

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration