2

I want to replace the string America/Adak with America/Jamaica by:

       perl -i -pe "s/$A/$B/"  /etc/sysconfig/clock 

please advice what need to update in the perl syntax ? ( the problem is that I have "/" so need to ignore this uniq character , what need to add to my perl syntax?

 A="America/Adak"
 B="America/Jamaica"
 CLOCK=/etc/sysconfig/clock

 perl -i -pe "s/$A/$B/" $CLOCK

 Bareword found where operator expected at -e line 1, near "s/America/Adak/America"
 syntax error at -e line 1, near "s/America/Adak/America"
 Execution of -e aborted due to compilation errors.

 more $CLOCK
 # The ZONE parameter is only evaluated by system-config-date.
 # The timezone of the system is defined by the contents of /etc/localtime.
 ZONE="America/Adak"
 UTC=true
 ARC=false
5

Use a different delimiter, for example:

perl -i -pe "s|$A|$B|" $CLOCK

See the perlre man page.

  • well done !!!!!!!!!!!!!!! – Diana Nov 17 '11 at 16:14
  • You can use most special characters as delimiters in perl and in sed. – Bruno9779 Apr 17 '15 at 1:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.