tags:

views:

44

answers:

3

Why do not this work? It finds all the other files but not this one. The only difference is that it has numbers in its name.

awk -F= '$1=="Icon" {print $2}' "/usr/share/applications/hildon/dropn900.desktop"

The file it uses..

 [Desktop Entry]
 Version=1.0.0
 Encoding=UTF-8
 Name=DropN900
 Comment=Python based DropBox client
 Exec=/opt/dropn900/dropn900.py
 Icon=dropn900
 X-Icon-path=/usr/share/icons
 X-Window-Icon=dropn900
 Type=Application
 X-Osso-Type=application/x-executable

It should give me the output of "dropn900" but doesn't.


If i do as suggested below..

awk -F= '$1==" Icon" {print $2}' "/usr/share/applications/hildon/fapman.desktop"
[Desktop Entry]
Encoding=UTF-8
Version=1.0
Type=Application
Name=Faster Application Manager
Exec=fapman.launch
Icon=fapman
X-Osso-Type=application/x-executable
X-Osso-Service=org.maemo.faster_application_manager
Categories=System;

This will not show..

The one suggested by Dennis gave the output.

dropn900
/usr/share/icons
dropn900

But i need just "dropn900" or the script will not work.

+2  A: 

Since you're using equals, not space, as the field separator, $1 is actually " Icon" with a leading space. Try

awk -F= '$1==" Icon" {print $2}'

on your file, and you'll see that the file having numbers in its name is really irrelevant.

Alex Martelli
Thanks! That did it ;)
AlMehdi
hmm.. but now doesn't my other work. like "fapman.desktop". It has the same line "Icon=fapman".
AlMehdi
@AlMehdi, if one value has a leading space and the other one doesn't, then you can't use `==` to compare them both to the same string! Don't focus on the filename, highlighted in this Q's very-wrong title, which is irrelevant. Use RE-matching or other ways to check instead.
Alex Martelli
@Alex Martelli: ghostdog74 solution worked so i am using that. And true.. i will change the topic.
AlMehdi
+1  A: 

If some of your files have leading whitespace on each line and some don't, this regex match may help:

awk -F= '$1 ~ " *Icon" {print $2}'
Dennis Williamson
Thanks again Dennis! This worked perfect.
AlMehdi
@dennis-williamson: It did work in terminal but when i do it in the script. It doesn't find all. Before it just missed the "dropn900" but now it misses five incl. the "dropn900".
AlMehdi
@Dennis Williamson: Maybe cause it finds to much.. it gets all the lines with "Icon" in it. Edit my post.
AlMehdi
+2  A: 
awk -F= '$1~/^ *Icon/ {print $2}' file
ghostdog74
@ghostdog74: Thanks but it did not work on "fapman" cause it doesn't have leading space.
AlMehdi
Sorry.. forgot the '*'.. now it might work. But i am not sure it is always the first "Icon" that is correct. That the '^' indicates.
AlMehdi
Strange.. now "fapman" gives the correct output in terminal. But don't show when i run it in the script. It's only "fapman" that don't show up of 13.
AlMehdi
My fault.. i went back and checked it more. It finds "fapman" as it should. I found out that this particular icon was in another folder. This is the one that worked for me.
AlMehdi