| Author |
Message |
RSH

Joined: 05 Sep 2011 Posts: 1564 Location: Germany
|
Posted: Wed 08 Feb 2012, 03:15 Post subject:
How to "grep-out" entries out of .desktop files? |
|
Hi,
| Code: | Name=$(grep "^Name=" abiword.desktop)
echo ${Name:5}
|
gives me the English Entry f.e. Name=AbiWord.
If i do try this with
| Code: | Name=$(grep "^Name[de]=" abiword.desktop)
echo ${Name:9}
|
i get error message "broken pipe" shown in terminal.
What do i have to do to get the entry of f.e. the German Name[de] or the French Name[fr] etc.?
Thanks
RSH
|
|
Back to top
|
|
 |
jpeps
Joined: 31 May 2008 Posts: 2449
|
Posted: Wed 08 Feb 2012, 04:11 Post subject:
Re: How to "grep-out" entries out of .desktop files? |
|
try:
| Code: |
Name=$(grep "^Name\[de\]=" abiword.desktop)
|
|
|
Back to top
|
|
 |
RSH

Joined: 05 Sep 2011 Posts: 1564 Location: Germany
|
Posted: Wed 08 Feb 2012, 04:30 Post subject:
Re: How to "grep-out" entries out of .desktop files? |
|
| jpeps wrote: | try:
| Code: |
Name=$(grep "^Name\[de\]=" abiword.desktop)
|
|
Oh ja, this is it!
Thank you, have been big trouble to me and now i do know more about the use of the "\" stuff.
|
|
Back to top
|
|
 |
jpeps
Joined: 31 May 2008 Posts: 2449
|
Posted: Wed 08 Feb 2012, 04:59 Post subject:
Re: How to "grep-out" entries out of .desktop files? |
|
| RSH wrote: | | ..and now i do know more about the use of the "\" stuff. |
They are our friend
|
|
Back to top
|
|
 |
RSH

Joined: 05 Sep 2011 Posts: 1564 Location: Germany
|
Posted: Wed 08 Feb 2012, 07:53 Post subject:
|
|
| Quote: | | They are our friend |
I do hope so.
I am sure you do have also a hint how to put the changed Name[de] back into the .desktop file. I know i did see something like this before (i believe somewhere in petspec?) but can not find it...
|
|
Back to top
|
|
 |
jpeps
Joined: 31 May 2008 Posts: 2449
|
Posted: Wed 08 Feb 2012, 12:48 Post subject:
|
|
| RSH wrote: | | Quote: | | They are our friend |
I do hope so.
I am sure you do have also a hint how to put the changed Name[de] back into the .desktop file. I know i did see something like this before (i believe somewhere in petspec?) but can not find it...  |
not sure what you're asking...maybe something like ?
sed -i "s/oldname/new/" file.desktop
|
|
Back to top
|
|
 |
RSH

Joined: 05 Sep 2011 Posts: 1564 Location: Germany
|
Posted: Wed 08 Feb 2012, 14:49 Post subject:
|
|
Yes, this is what i mean.
I did try
| Code: | put_in_file() {
echo Name=$ITEM_NAME
echo Name[$lang_category]=$ITEM_DENAME
if [ -f "$APPLPATH/$TREE_INCLUDED_ITEMS.desktop" ]; then
echo "$APPLPATH/$TREE_INCLUDED_ITEMS.desktop"
fi
sed -i "s/$ITEM_NAME/$ITEM_DENAME/" $APPLPATH/$TREE_INCLUDED_ITEMS.desktop
}
export -f put_in_file
|
All values are right (echo shows me) but
| Code: | | sed -i "s/$ITEM_NAME/$ITEM_DENAME/" $APPLPATH/$TREE_INCLUDED_ITEMS.desktop |
and
| Code: | | sed -i "s|$ITEM_NAME|$ITEM_DENAME|" $APPLPATH/$TREE_INCLUDED_ITEMS.desktop |
does not work.
|
|
Back to top
|
|
 |
technosaurus

Joined: 18 May 2008 Posts: 3845
|
Posted: Wed 08 Feb 2012, 17:35 Post subject:
|
|
from jwm_menu_create - I didn't use grep or sed though
| Code: | [ $myLANG ] || myLANG=${LANGUAGE%% *}
[ $myLANG ] || myLANG=${LANG%_*}
[ -f /usr/share/locale/$myLANG/LC_MESSAGES/jwm ] && . /usr/share/locale/$myLANG/LC_MESSAGES/jwm
for DESKTOP_FILE in /usr/share/applications/*.desktop ; do
ICON="" CATS="" NAME="" EXEC="" LINE="" #prevent carryover from previous file
while read LINE || [ "$LINE" ]; do
case $LINE in
Name=*|Name?${myLANG%_*}?=*) NAME="${LINE#*=}"'' ;; # sc0ttman... should use "Name[$myLANG]=" if found
# Comment=*|Comment?${LANG%_*}?=*) COMMENT="${LINE#*=}"'' ;; #jwm doesn't support tooltips on menu items yet ... uncomment this if it ever does
Icon=*) ICON="${LINE#*=}"'' ;;
Categories=*) CATS="${LINE#*=}"'' ;;
Exec=*) EXEC="${LINE#*=}"'' ;;
esac
done < $DESKTOP_FILE
#once you have all of those you can echo it back to the file here:
done |
Edit: It looks like you may be trying to duplicate this:
http://www.murga-linux.com/puppy/viewtopic.php?t=70804
_________________ Puppy Web Desktop Now with pet packages - Pet Packaging 100 & 101
|
|
Back to top
|
|
 |
jpeps
Joined: 31 May 2008 Posts: 2449
|
Posted: Wed 08 Feb 2012, 23:47 Post subject:
|
|
| RSH wrote: |
| Code: | | sed -i "s/$ITEM_NAME/$ITEM_DENAME/" $APPLPATH/$TREE_INCLUDED_ITEMS.desktop |
does not work.  |
That probably means that something in the item_names needs an escape or the path/app.desktop name is incorrect.
|
|
Back to top
|
|
 |
RSH

Joined: 05 Sep 2011 Posts: 1564 Location: Germany
|
Posted: Thu 09 Feb 2012, 07:32 Post subject:
|
|
| jpeps wrote: | | That probably means that something in the item_names needs an escape or the path/app.desktop name is incorrect. |
One of the item_names is :"AbiWord Textverarbeitung" (without the quotes but with the space between the two words).
What is an escape? How do i do this?
|
|
Back to top
|
|
 |
jpeps
Joined: 31 May 2008 Posts: 2449
|
Posted: Thu 09 Feb 2012, 11:24 Post subject:
|
|
| RSH wrote: | | jpeps wrote: | | That probably means that something in the item_names needs an escape or the path/app.desktop name is incorrect. |
One of the item_names is :"AbiWord Textverarbeitung" (without the quotes but with the space between the two words).
What is an escape? How do i do this? |
It should work, provided your variable is defined correcty. ( eg new="Abiword Textverarbeitung" ) You might try:
sed -i "s/${old}/${new}/ "
You can test it out with "sed -e", which will print without making any change.
An escape is our friend "\" You can also escape a space:
new="Abiword\ Textverarbeitung"
|
|
Back to top
|
|
 |
|