0

I'm using ksh to search through a log file and remove any passwords that might have been logged there. The password may contain special characters so wanted to use perl & /Q /E to to treat the string just as normal character. The perl command works on the command line

perl -pe  's/\Q123.adc*{eft{\ther/xxx/g' dirty.txt > clean.txt

but when I put it in the ksh using variables it's not removing the passwords.

#!/bin/ksh
#set -x

#### File Definitions
export LOG_FILE=dirty.txt
export LOG_FILE2=clean.txt

export STR=123.adc*{eft{\ther

echo $STR
export NEW_STR=xxx
perl -pe  's/\Q$ENV{STR}/$ENV{NEW_STR}/g' $LOG_FILE  > $LOG_FILE2
nuala
  • 1
  • 2
  • See also https://stackoverflow.com/questions/6964536/accessing-shell-variable-in-a-perl-program – tripleee Jul 22 '20 at 08:27
  • No, that doesn't work on the command line either. You are accessing uninitialized Perl variables instead of the appropriate env variables. Replace `${STR}` and `$NEW_STR` with `$ENV{STR}` and `$ENV{NEW_STR}`. – ikegami Jul 22 '20 at 08:33
  • Importantly, note that you should NOT start using double-quotes as @tripleee might be implying. Trying to generate Perl code from the shell is a foolish venture. – ikegami Jul 22 '20 at 08:33
  • By the way, a trailing `\E` can be left out – ikegami Jul 22 '20 at 08:36
  • hi - thanks for suggestions. Fixed and showing command line version. @ikegami I put in your suggestion of ENV{ } but it's still not working. – nuala Jul 22 '20 at 15:34
  • @nuala, In your original version, you were searching for `123.adc*{eft{\ther`. But you put `123.adc*{eft{ther` in `$STR`. Use single quotes like you did in your original version – ikegami Jul 23 '20 at 01:21

0 Answers0