Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Mon 20 May 2013, 10:19
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
How to "grep-out" entries out of .desktop files?
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [11 Posts]  
Author Message
RSH


Joined: 05 Sep 2011
Posts: 1564
Location: Germany

PostPosted: 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
View user's profile Send private message 
jpeps

Joined: 31 May 2008
Posts: 2421

PostPosted: 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
View user's profile Send private message 
RSH


Joined: 05 Sep 2011
Posts: 1564
Location: Germany

PostPosted: 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! Cool

Thank you, have been big trouble to me and now i do know more about the use of the "\" stuff.
Back to top
View user's profile Send private message 
jpeps

Joined: 31 May 2008
Posts: 2421

PostPosted: 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 Smile
Back to top
View user's profile Send private message 
RSH


Joined: 05 Sep 2011
Posts: 1564
Location: Germany

PostPosted: Wed 08 Feb 2012, 07:53    Post subject:  

Quote:
They are our friend

I do hope so. Smile

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... Confused
Back to top
View user's profile Send private message 
jpeps

Joined: 31 May 2008
Posts: 2421

PostPosted: Wed 08 Feb 2012, 12:48    Post subject:  

RSH wrote:
Quote:
They are our friend

I do hope so. Smile

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... Confused

not sure what you're asking...maybe something like ?

sed -i "s/oldname/new/" file.desktop
Back to top
View user's profile Send private message 
RSH


Joined: 05 Sep 2011
Posts: 1564
Location: Germany

PostPosted: 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. Shocked
Back to top
View user's profile Send private message 
technosaurus


Joined: 18 May 2008
Posts: 3843

PostPosted: 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
View user's profile Send private message 
jpeps

Joined: 31 May 2008
Posts: 2421

PostPosted: 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. Shocked


That probably means that something in the item_names needs an escape or the path/app.desktop name is incorrect.
Back to top
View user's profile Send private message 
RSH


Joined: 05 Sep 2011
Posts: 1564
Location: Germany

PostPosted: 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
View user's profile Send private message 
jpeps

Joined: 31 May 2008
Posts: 2421

PostPosted: 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
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [11 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0725s ][ Queries: 12 (0.0042s) ][ GZIP on ]