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 Fri 24 Oct 2014, 13:23
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
Replace Text Section using Bash
Post_new_topic   Reply_to_topic View_previous_topic :: View_next_topic
Page 1 of 1 Posts_count  
Author Message
RSH


Joined: 05 Sep 2011
Posts: 2420
Location: Germany

PostPosted: Thu 17 Jan 2013, 12:41    Post_subject:  Replace Text Section using Bash  

Hi.

I want to replace the OrigFbPanel-Section with the NewFbPanel-Section in the code below. Presented Code-"solution" did not work.

Any hint, what I'm doing wrong?

Thanks,

RSH

Quote:
#!/bin/bash -a
#------------------------------------------------------------------------------
# Leeres Skript für LazY Puppy
# 2012-12-28 RSH for LazY Puppy
#------------------------------------------------------------------------------

# Menu Hierarchy
HirFile=/usr/sbin/pfbpanel
MyHirFile=/tmp/TempInstall/add2fbpanel
MyHir=`cat $MyHirFile`
TempFile=/tmp/TempInstall/add2fbpanel
HirTempFile=/new_pfbpanel
MYHIRINSERT="true"
MYHIRINSERT2="true"
MYHIRINSERT3="true"

OrigFbPanelItems=" fbpanel-xdgmenu /etc/xdg/menus/puppy-desktop.menu >> /tmp/fbpanel-menu
fbpanel-xdgmenu /etc/xdg/menus/puppy-system.menu >> /tmp/fbpanel-menu
fbpanel-xdgmenu /etc/xdg/menus/puppy-setup.menu >> /tmp/fbpanel-menu
fbpanel-xdgmenu /etc/xdg/menus/puppy-utility.menu >> /tmp/fbpanel-menu
fbpanel-xdgmenu /etc/xdg/menus/puppy-filesystem.menu >> /tmp/fbpanel-menu
fbpanel-xdgmenu /etc/xdg/menus/puppy-graphic.menu >> /tmp/fbpanel-menu
fbpanel-xdgmenu /etc/xdg/menus/puppy-document.menu >> /tmp/fbpanel-menu
fbpanel-xdgmenu /etc/xdg/menus/puppy-calculate.menu >> /tmp/fbpanel-menu
fbpanel-xdgmenu /etc/xdg/menus/puppy-personal.menu >> /tmp/fbpanel-menu
fbpanel-xdgmenu /etc/xdg/menus/puppy-network.menu >> /tmp/fbpanel-menu
fbpanel-xdgmenu /etc/xdg/menus/puppy-internet.menu >> /tmp/fbpanel-menu
fbpanel-xdgmenu /etc/xdg/menus/puppy-multimedia.menu >> /tmp/fbpanel-menu
fbpanel-xdgmenu /etc/xdg/menus/puppy-fun.menu >> /tmp/fbpanel-menu"

NewFbPanelItems=" fbpanel-xdgmenu /etc/xdg/menus/puppy-desktop.menu >> /tmp/fbpanel-menu
fbpanel-xdgmenu /etc/xdg/menus/puppy-system.menu >> /tmp/fbpanel-menu
fbpanel-xdgmenu /etc/xdg/menus/puppy-setup.menu >> /tmp/fbpanel-menu
echo separator \{ >> /tmp/fbpanel-menu
echo \} >> /tmp/fbpanel-menu
fbpanel-xdgmenu /etc/xdg/menus/puppy-vsppup.menu >> /tmp/fbpanel-menu
echo separator \{ >> /tmp/fbpanel-menu
echo \} >> /tmp/fbpanel-menu
fbpanel-xdgmenu /etc/xdg/menus/puppy-utility.menu >> /tmp/fbpanel-menu
fbpanel-xdgmenu /etc/xdg/menus/puppy-filesystem.menu >> /tmp/fbpanel-menu
fbpanel-xdgmenu /etc/xdg/menus/puppy-graphic.menu >> /tmp/fbpanel-menu
fbpanel-xdgmenu /etc/xdg/menus/puppy-document.menu >> /tmp/fbpanel-menu
fbpanel-xdgmenu /etc/xdg/menus/puppy-calculate.menu >> /tmp/fbpanel-menu
fbpanel-xdgmenu /etc/xdg/menus/puppy-personal.menu >> /tmp/fbpanel-menu
fbpanel-xdgmenu /etc/xdg/menus/puppy-network.menu >> /tmp/fbpanel-menu
fbpanel-xdgmenu /etc/xdg/menus/puppy-internet.menu >> /tmp/fbpanel-menu
fbpanel-xdgmenu /etc/xdg/menus/puppy-multimedia.menu >> /tmp/fbpanel-menu
fbpanel-xdgmenu /etc/xdg/menus/puppy-fun.menu >> /tmp/fbpanel-menu"

sed -i 's|'$OrigFbPanelItems'|'$NewFbPanelItems'|' $HirFile


exit 0

#------------------------------------------------------------------------------
# End
#------------------------------------------------------------------------------


Terminal gives me an unterminated s command message.

_________________
LazY Puppy
RSH's DNA
SARA B.
Back to top
View user's profile Send_private_message 
seaside

Joined: 11 Apr 2007
Posts: 887

PostPosted: Thu 17 Jan 2013, 13:12    Post_subject:  

RSH,

Maybe double quotes-
Code:

sed -i 's|"OrigFbPanelItems"|"NewFbPanelItems"|' $HirFile


Cheers,
s
Back to top
View user's profile Send_private_message 
RSH


Joined: 05 Sep 2011
Posts: 2420
Location: Germany

PostPosted: Thu 17 Jan 2013, 13:33    Post_subject:  

Unfortunately not. Crying or Very sad

I have tried already this:
Code:
sed -i 's|'$OrigFbPanelItems'|'$NewFbPanelItems'|' $HirFile

and this:
Code:
sed -i 's|"OrigFbPanelItems"|"NewFbPanelItems"|' $HirFile

and also this:
Code:
sed -i 's|'"OrigFbPanelItems"'|'"NewFbPanelItems"'|' $HirFile

Results are equal:

sed: -e expression #1, char 74: unterminated 's' command - or: the whole $HirFile is scrolling through the terminal (the just double quoted version)

char changes between 2 (single quoted) and 74 (songle-double quoted) Question

_________________
LazY Puppy
RSH's DNA
SARA B.
Back to top
View user's profile Send_private_message 
amigo

Joined: 02 Apr 2007
Posts: 2261

PostPosted: Thu 17 Jan 2013, 13:47    Post_subject:  

You need to use double quotes on the *outside* part of the sed command. Since the replace values are represented as variables they should be expanded by the shell before being passed to sed. Your use of single quotes prevents the shell from doing this.
Should do what you want:
Code:
sed -i "s|$OrigFbPanelItems|$NewFbPanelItems|" $HirFile
Back to top
View user's profile Send_private_message 
RSH


Joined: 05 Sep 2011
Posts: 2420
Location: Germany

PostPosted: Thu 17 Jan 2013, 14:17    Post_subject:  

amigo wrote:
You need to use double quotes on the *outside* part of the sed command. Since the replace values are represented as variables they should be expanded by the shell before being passed to sed. Your use of single quotes prevents the shell from doing this.
Should do what you want:
Code:
sed -i "s|$OrigFbPanelItems|$NewFbPanelItems|" $HirFile

Sorry, unfortunately doesn't work also.

sed: -e expression #1, char 74: unterminated 's' command

_________________
LazY Puppy
RSH's DNA
SARA B.
Back to top
View user's profile Send_private_message 
seaside

Joined: 11 Apr 2007
Posts: 887

PostPosted: Thu 17 Jan 2013, 14:37    Post_subject:  

RSH,

It looks like the last quoting by Amigo is right, so there is probably something in the variables causing the error.

Code:
# OrigFbPanelItems='one two three'
# NewFbPanelItems='four five six'
# HirFile='one two three'
# sed  "s|$OrigFbPanelItems|$NewFbPanelItems|" <<<"$HirFile"
four five six


One down, only a zillion more to go Very Happy

Cheers,
s
Back to top
View user's profile Send_private_message 
amigo

Joined: 02 Apr 2007
Posts: 2261

PostPosted: Thu 17 Jan 2013, 14:46    Post_subject:  

May be simpler to simply read the original file line-by-line while writing the contents to a new file and inserting your changes at the right time/place. May be that you need to escape the instances of '>' chars. I believe I'd use a nice little read/check-for-right-place/write op for that. sed could be made useful to do it, but pure shell-manipulation will be much simpler too achieve

Yeah, shell scripting can be used by Lazy people, but as soon as you want to do some serious changes, you can't be a Lazy coder. It's kind like the difference between being a Slacker and being the guy who creates Slack -or vice-versa. If you want to make things simple for your user, then you need to do complex things for them (very anti-Slack behaviour). Or, *you* can be the Slacker and makes users do things for themselves. Slack-user!=Slack-creator. Alles Klar?
Back to top
View user's profile Send_private_message 
RSH


Joined: 05 Sep 2011
Posts: 2420
Location: Germany

PostPosted: Thu 17 Jan 2013, 15:05    Post_subject:  

Quote:
May be simpler to simply read the original file line-by-line while writing the contents to a new file and inserting your changes at the right time/place. May be that you need to escape the instances of '>' chars. I believe I'd use a nice little read/check-for-right-place/write op for that. sed could be made useful to do it, but pure shell-manipulation will be much simpler too achieve

Exactly this I've tried before. It has worked for the /usr/bin/obmenu-refresh file, but on the pfbpanel file it loses every "\" in every line, somewhere between reading it and writing it to the temp file.

That's why I've come back to this here.

I've gotten some sed lines before from seaside and L18L on another issue, so I thought, why not try to use something similar like this?
Code:
sed -i 's/<keyboard>/<keyboard>my code/' rc.xml

So, by now, it looks like the One-Click-VSP-Puppy-Builder will be a One-Click-plus-One-manual-step-VSP-Puppy-Builder. Laughing

Thanks for the help

_________________
LazY Puppy
RSH's DNA
SARA B.
Back to top
View user's profile Send_private_message 
Display_posts:   Sort by:   
Page 1 of 1 Posts_count  
Post_new_topic   Reply_to_topic View_previous_topic :: View_next_topic
 Forum index » Off-Topic Area » Programming
Jump to:  

Rules_post_cannot
Rules_reply_cannot
Rules_edit_cannot
Rules_delete_cannot
Rules_vote_cannot
You cannot attach files in this forum
You can download files in this forum


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