Unable to update the string in a file trough case command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Unable to update the string in a file trough case command
# 1  
Old 08-02-2014
Unable to update the string in a file trough case command

Hi All,

my requirement is first search the line and updated stg value with the user input value.
Code:
ws.rsp.url=https://rt930.rsp-stg.cb.info53.com/RSP/RAFT^M

stg is not fixed string it may varies.So i used the below command for it
Code:
rsp=`cat properties | grep ^ws.rsp.url= | awk -F"/" '{print $3}' | awk -F"-" '{print $2}'|awk -F"." '{print $1}'`

when i use the below command through command line it's working fine.But when use in code it's not working.
Code:
"cat properties | grep ^ws.rsp.url | perl -pi -e 's/stg/$dev/' properties"

My code:
Code:
select env in  dev stg qa
do
if [ $env != "" ]; then
      echo "SELECTED ENVIRONMENT IS : $env"
      break
   else
      echo "Illegal selection."
fi
done
echo " "
Line3=`cat properties | grep ^ws.rsp.url=`
echo "Current rsp url is as follow.Please make selection carefully"
echo $Line3
echo " "
echo "Would you like to add any "stg dev qa " tip to point rsp url (y/n)?"
read yn
    case $yn in
        [Yy]* )
    rsp=`cat properties | grep ^ws.rsp.url= | awk -F"/" '{print $3}' | awk -F"-" '{print $2}'|awk -F"." '{print $1}'`
    echo $rsp
    echo $env
    cat properties | grep ^ws.rsp.url | perl -pi -e 's/${rsp}/${env}/' properties
    LINE12=`cat properties | grep ^ws.rsp.url`
     echo "changed rsp url as below"
      echo $LINE12;;
        [Nn]* )
        echo "As per you selection it's not required to change rsp url"
         ;;
        * )
    esac
echo " rsp url is ready now"

file is too large so mentioned only the line of the file need to be updated
---------
Code:
ws.clairMail=https;//
rewards=https;//
ws.rsp.url=https://rt930.rsp-stg.cb.info53.com/RSP/RAFT^M

Please let me know if you need some moredetails about my requirement.I am using AIX.
# 2  
Old 08-03-2014
grep doesn't need cat to read files, it can open them it's self. No need for perl or awk, sed can find and replace text.

Try this updated script:

Code:
select env in  dev stg qa
do
if [ $env != "" ]; then
      echo "SELECTED ENVIRONMENT IS : $env"
      break
   else
      echo "Illegal selection."
fi
done
echo " "
Line3=`grep ^ws.rsp.url= properties`
echo "Current rsp url is as follow.Please make selection carefully"
echo $Line3
echo " "
echo "Would you like to add any "stg dev qa " tip to point rsp url (y/n)?"
read yn
case $yn in
    [Yy]*)
       rsp=`sed -n '/^ws.rsp.url=/s/^[^-]*-\([^.]*\)\..*/\1/p' properties`
       echo $rsp
       echo $env
       sed "/^ws.rsp.url/s:$rsp:$env:" properties > /tmp/properties.$$
       mv /tmp/properties.$$ properties
       LINE12=`grep ^ws.rsp.url properties`
       echo "changed rsp url as below"
       echo $LINE12
       ;;
    [Nn]*)
       echo "As per you selection it's not required to change rsp url"
       ;;
    *)
esac 
echo " rsp url is ready now"

Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Unable to attach a .txt file or .log file to mail and mailx command

Hi, I am trying to attach a .log file or .txt file to mail command to send an email once my ksh script executed. I am unable to use mutt command as it has been not installed and i am not supposed to install it. I have tried many ways by googling which has not helped me to succeed. Here is my... (5 Replies)
Discussion started by: Samah
5 Replies

2. Shell Programming and Scripting

Test command non case specific string comparision

Hi, I want to do caseless string comparision using test command for eg: Ind_f="y" test "$Ind_f" == "y|Y" i tried , ** , nothing worked. any thoughts on how to do case insensitive string comparison using test command without converting to any particular case using typeset or tr? (8 Replies)
Discussion started by: Kulasekar
8 Replies

3. UNIX for Dummies Questions & Answers

UNABLE TO UPDATE! HELP!

I just installed the latest version of ubuntu and I can't run the update manager without getting an error message. Im not sure what info i need to post so i can get help so just tell me if i need to post info because i would like to use ubuntu. (2 Replies)
Discussion started by: Brandyn
2 Replies

4. Shell Programming and Scripting

convert file names to upper case using tr command in Unix

Hi All, Need to convert file names to upper case using tr command in Unix. In a folder -> /apps/dd01/misc there are two files like: pi-abcd.pdf pi-efgh.pdf The output of should be like: pi-ABCD.pdf pi-EFGH.pdf I have used the command to work for a single file at a time... (3 Replies)
Discussion started by: a1_win
3 Replies

5. UNIX for Dummies Questions & Answers

update file command help

please explain this update to the webcache.xml file ( attached) sorry i come from a windows env thank you ************* echo -n "7. Updating webcache.xml file..." set line_num = `grep -n "</CACHEABILITY>" $ORACLE_HOME/webcache/webcache.xml | tail -1 | cut -d : -f 1` head -`expr $line_num... (0 Replies)
Discussion started by: maoro
0 Replies

6. Solaris

Unable to update the Crontab

Hi Everyone, Each time I do update the crontab, it gets reset after exiting from the telnet session. I'm using Solaris 2.8 So it goes like this: Step 1: Login as root, from a telnet session Step 2: Crontab -e (I make modification) Step 3: Save and exit Step 4: Type crontab -l , changes... (4 Replies)
Discussion started by: Jeremy3
4 Replies

7. UNIX for Dummies Questions & Answers

lower case to upper case string conversion in shell script

How can convert a Lower case variable value to an upper case in the kron shell script. (3 Replies)
Discussion started by: dchalavadi
3 Replies
Login or Register to Ask a Question