Author |
Message |
RSH

Joined: 05 Sep 2011 Posts: 2420 Location: Germany
|
Posted: 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
|
|
 |
seaside
Joined: 11 Apr 2007 Posts: 917
|
Posted: Thu 17 Jan 2013, 13:12 Post subject:
|
|
RSH,
Maybe double quotes-
Code: |
sed -i 's|"OrigFbPanelItems"|"NewFbPanelItems"|' $HirFile
|
Cheers,
s
|
Back to top
|
|
 |
RSH

Joined: 05 Sep 2011 Posts: 2420 Location: Germany
|
Posted: Thu 17 Jan 2013, 13:33 Post subject:
|
|
Unfortunately not.
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)
_________________ LazY Puppy
RSH's DNA
SARA B.
|
Back to top
|
|
 |
amigo
Joined: 02 Apr 2007 Posts: 2641
|
Posted: 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
|
|
 |
RSH

Joined: 05 Sep 2011 Posts: 2420 Location: Germany
|
Posted: 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
|
|
 |
seaside
Joined: 11 Apr 2007 Posts: 917
|
Posted: 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
Cheers,
s
|
Back to top
|
|
 |
amigo
Joined: 02 Apr 2007 Posts: 2641
|
Posted: 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
|
|
 |
RSH

Joined: 05 Sep 2011 Posts: 2420 Location: Germany
|
Posted: 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.
Thanks for the help
_________________ LazY Puppy
RSH's DNA
SARA B.
|
Back to top
|
|
 |
|