LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (http://www.linuxquestions.org/questions/linux-general-1/)
-   -   Cli command to search and print file content without printing searchword? (http://www.linuxquestions.org/questions/linux-general-1/cli-command-to-search-and-print-file-content-without-printing-searchword-4175453163/)

linuxlicious 03-07-2013 01:55 PM

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?

Snark1994 03-07-2013 03:27 PM

Could you give a specific example? What about:

Code:

grep "foo" *.desktop | sed 's/foo//g'
?

Habitual 03-07-2013 03:59 PM

Code:

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


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