I would like to use a one line Perl command to change data in a Bash variable. I think the problem is that the Perl one liner isn't receiving the piped in data.
I know about the bash change variable
i.e. findString=${findString//\//\\/}
I'm curious about getting Perl to work too. I do not know Perl so keep it simple.
To be clear, these two lines are not working: I would like the tabs in the text to be changed to \t. I would like any Unix line ends to be changed to \n.
findString=$(cat "${findString}" | perl -0777pe 's/\t/\\t/g')
findString=$(cat "${findString}" | perl -0777pe 's/\n/\\n/g')
Here is my bash code:
#!/bin/bash
#The idea here is to change tab to \n
# and line End to \n
# debug info
export PS4='+(${BASH_SOURCE}:${LINENO}):'
# trace all the lines
#set -o xtrace
echo "---------------------- start ----------------------------------------"
# string to change.
# chops off the last \n
read -d '' findString <<"EOFEOFEOF"
# Usage: /Users/mac/Sites/bithoist/commandLine/BitHoist/BitHoist-PPC-MacOS-X [options] input... < input > output
# Options and inputs may be intermixed
-stdin # Use standard input as input file
-offset nn # Offset next input file data by nn
EOFEOFEOF
findString=$(cat "${findString}" | perl -0777pe 's/\t/\\t/g')
findString=$(cat "${findString}" | perl -0777pe 's/\n/\\n/g')
echo "------------> findString of length ${#findString} is:"
echo -E "${findString}"
echo
echo, notcat, in those commands.