awk 命令在看起来不同的文件中查找
为什么这行不通?它找到所有其他文件,但找不到这个文件。唯一的区别是它的名称中有数字。
awk -F= '$1=="Icon" {print $2}' "/usr/share/applications/hildon/dropn900.desktop"
它使用的文件..
[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
它应该给我“dropn900”的输出,但没有。
如果我按照下面的建议进行操作..
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;
这将不会显示..
丹尼斯建议的给出了输出。
dropn900 /usr/share/icons dropn900
但我只需要“dropn900”,否则脚本将无法工作。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
由于您使用等于而不是空格作为字段分隔符,因此
$1
实际上是" Icon"
带有前导空格。尝试一下您的文件,您会发现名称中包含数字的文件确实无关紧要。
Since you're using equals, not space, as the field separator,
$1
is actually" Icon"
with a leading space. Tryon your file, and you'll see that the file having numbers in its name is really irrelevant.
如果您的某些文件每行都有前导空格,而另一些则没有,则此正则表达式匹配可能会有所帮助:
If some of your files have leading whitespace on each line and some don't, this regex match may help: