Re: Sed in Script problem using expr

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 11/14/06, Paul Ward <pnward@xxxxxxxxxxxxxx> wrote:
Hi All,

Can anyone help me with the following script problem please its driving me nuts.

I am trying to make a script capable of commenting and uncommenting
lines on a custom config file similar to this.

myconf:
#Months
02
04
06
#08
10
12

myscript.sh:
#!/bin/bash
echo "Enter a number from 1 - 10 to sed"
read i
NUM=`expr $i - 2`; printf %02d $NUM ; echo " "
echo "I will sed this " $NUM
read
sed '/$NUM/s/^#//' myconf > newconf

When you enter the number 10 you lose the decimal point after the expr
sum subtracts 2 it is still 08 but on the sed I think it uses 8 not 08
so the sed line fails
Is there another way to do this?

Any other methods would be welcome.
once you add `` ' `` single quote shell will not recognize the variable ,
I had this problem the only way I found is to use "sed -f" and
generate sed scripts on the run time on temp dir then run sed -f .

example
cat << EOS
sed statments
$NUM
sed statments
num.sed
sed -f num.sed
rm -f num.sed

hope this will help,I think there is smart way to do it.


Thanks

Paul

--
fedora-list mailing list
fedora-list@xxxxxxxxxx
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list

--
Diaa Radwan,RHCE

--
fedora-list mailing list
fedora-list@xxxxxxxxxx
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
[Index of Archives]     [Older Fedora Users]     [Fedora Announce]     [Fedora Package Announce]     [EPEL Announce]     [Fedora Magazine]     [Fedora News]     [Fedora Summer Coding]     [Fedora Laptop]     [Fedora Cloud]     [Fedora Advisory Board]     [Fedora Education]     [Fedora Security]     [Fedora Scitech]     [Fedora Robotics]     [Fedora Maintainers]     [Fedora Infrastructure]     [Fedora Websites]     [Anaconda Devel]     [Fedora Devel Java]     [Fedora Legacy]     [Fedora Desktop]     [Fedora Fonts]     [ATA RAID]     [Fedora Marketing]     [Fedora Management Tools]     [Fedora Mentors]     [SSH]     [Fedora Package Review]     [Fedora R Devel]     [Fedora PHP Devel]     [Kickstart]     [Fedora Music]     [Fedora Packaging]     [Centos]     [Fedora SELinux]     [Fedora Legal]     [Fedora Kernel]     [Fedora OCaml]     [Coolkey]     [Virtualization Tools]     [ET Management Tools]     [Yum Users]     [Tux]     [Yosemite News]     [Gnome Users]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [Asterisk PBX]     [Fedora Sparc]     [Fedora Universal Network Connector]     [Libvirt Users]     [Fedora ARM]

  Powered by Linux