How to insert # with sed
-
- Posts: 98
- Joined: 2019/12/11 03:51:58
How to insert # with sed
Hi,
I hope to insert # to starting of copy_old_man the below the shell script. copy_old_man is a function which defined in the earlier and many functions are defined in this shell script also.
[BEFORE]
create_man () {
copy_old_man
.
.
}
[AFTER]
create_man () {
# copy_old_man
.
.
}
BR.
I hope to insert # to starting of copy_old_man the below the shell script. copy_old_man is a function which defined in the earlier and many functions are defined in this shell script also.
[BEFORE]
create_man () {
copy_old_man
.
.
}
[AFTER]
create_man () {
# copy_old_man
.
.
}
BR.
Re: How to insert # with sed
Should be something like:
sed -i '/^copy_old_man/s//#&/' /path/to/file
I'd test with sed -e first though to be safe.
sed -i '/^copy_old_man/s//#&/' /path/to/file
I'd test with sed -e first though to be safe.
-
- Posts: 98
- Joined: 2019/12/11 03:51:58
Re: How to insert # with sed
Hi,
Thanks to reply, but it doesn't work. sorry. it add # to function definition of copy_old_man. I hope add # calling copy_old_man in the create_man, not definition.
BR.
Re: How to insert # with sed
We can't see what is in your file. How could we possibly suggest a regexp that matches (only) the correct line?
-
- Posts: 98
- Joined: 2019/12/11 03:51:58
Re: How to insert # with sed
Hi jlehtone,
I add snippet of my shell script.
In the script I hope to disable to call 'copy_guest_tools' in 'create_newiso' by adding comment, # to starting of line of copy_guest_tools with sed or awk.#!/bin/sh
copy_guest_tools() {
echo "Copying $GUESTTOOLS"
echo "Initiallizing and fetching submodule $GUESTTOOLS"
git submodule init
git submodule update
cp -R ./$GUESTTOOLS/ $DVD_LAYOUT/
}
modify_boot_menu() {
echo "Modifying grub boot menu"
cp ./isolinux.cfg $DVD_LAYOUT/isolinux/
}
cleanup_layout() {
echo "Cleaning up $DVD_LAYOUT"
find $DVD_LAYOUT -name TRANS.TBL -exec rm '{}' +
COMPS_XML=$(find $DVD_LAYOUT/repodata -name '*-minimal-x86_64-comps.xml' ! -name 'repomd.xml' -exec basename {} \;)
mv $DVD_LAYOUT/repodata/$COMPS_XML $DVD_LAYOUT/repodata/comps.xml
find $DVD_LAYOUT/repodata -type f ! -name 'comps.xml' -exec rm '{}' +
}
create_newiso() {
copy_guest_tools
modify_boot_menu
cleanup_layout
}
I have tried to find "create_newiso()" first, then I have tried to add # to next line, but, I can not find how to do it.
BR.
Re: How to insert # with sed
Ok, the lines are:
and you want to match the line that does not have parenthese after the tools?
What do you get with:
Code: Select all
copy_guest_tools() {
copy_guest_tools
What do you get with:
Code: Select all
sed "s/^\(copy_guest_tools[^(]\)/# \1/"
-
- Posts: 98
- Joined: 2019/12/11 03:51:58
Re: How to insert # with sed
Hi jlehtone,jlehtone wrote: ↑2020/06/09 08:57:22Ok, the lines are:and you want to match the line that does not have parenthese after the tools?Code: Select all
copy_guest_tools() { copy_guest_tools
What do you get with:Code: Select all
sed "s/^\(copy_guest_tools[^(]\)/# \1/"
Sorry for confusing you.
I hope to only add # to in front of copy_guest_tools in next line create_newiso() { .
BR.
-
- Posts: 98
- Joined: 2019/12/11 03:51:58
Re: How to insert # with sed
Hi,
I resolve it.
sed '/^create_newiso\(\)/,/^END/s/copy_guest_tools/\#copy_guest_tools/'
BR.
I resolve it.
sed '/^create_newiso\(\)/,/^END/s/copy_guest_tools/\#copy_guest_tools/'
BR.