need help to replace line in shell script
Below is the file i need to replace third line with genarated output from script
My file: [root@isge ~]# cat /root/sge_scripts/night_sched_conf algorithm default schedule_interval 0:0:05 maxujobs 12 queue_sort_method seqno I want to replace in third line maxujobs number 12 to my script generated value (range value in below script) My script: #!/bin/sh export SGE_ROOT=/opt/sge source=/opt/sge/defalt/common/settings.sh delete=1 total=`qstat -u "*" | awk ' { print $4 } ' | sort | uniq | wc -l` total_users=$((total - delete)) case $total_users in 1) range=18;; 2) range=9 ;; 3) range=7 ;; 4) range=6 ;; 5) range=5 ;; 6) range=4 ;; 7) range=3 ;; 8) range=3 ;; 9) range=2 ;; 10) range=2 ;; 11) range=2 ;; 12) range=2 ;; 13) range=1 ;; 14) range=1 ;; 15) range=1 ;; 16) range=1 ;; 18) range=1 ;; 19) range=1 ;; 20) range=1 ;; 21) range=1 ;; 22) range=1 ;; 23) range=1 ;; 24) range=1 ;; 25) range=1 ;; 26) range=1 ;; 27) range=1 ;; 28) range=1 ;; 29) range=1 ;; 30) range=1 ;; 31) range=1 ;; 32) range=1 ;; 33) range=1 ;; 34) range=1 ;; *) echo "INVALID NUMBER!" ;; esac current=`cat /root/sge_scripts/night_sched_conf | awk ' /maxujobs/ { print $2 } '` if [ "$range" != "$current" ] then sed -i '3s/.*/maxujobs "$range"/' /root/sge_scripts/night_sched_conf fi Please help me |
What exactly is the problem? Is the substitution not being made?
|
I cant able to pass range value in substitutions
sed -i '3s/.*/maxujobs "$range"/' /root/sge_scripts/night_sched_conf its not working instead value its its substitution $range itself |
Try this:
Code:
sed -i '3s/.*/maxujobs '"$range/" /root/sge_scripts/night_sched_conf |
Why do you have quotes around $range, when none is present in the original? Do you want the replacement to have quotes?
If not, and you only want the number, try this: Code:
sed -i "3s/.*/maxujobs ${range}/" /root/sge_scripts/night_sched_conf Code:
sed -i "3s/.*/maxujobs \"${range}\"/" /root/sge_scripts/night_sched_conf I always use brackets for safety. The type of quote - single or double - does matter to the shell (usually bash or dash by default) when doing substitutions. Using bash/dash, a variable name in single quotes will not be expanded to its value, whereas in a double quote the variable will be expanded. |
Thanks for your replies
|
If this solves your problem, please, mark the thread as solved.
|
All times are GMT -5. The time now is 05:29 PM. |