Bash/Sed implementation of PHP add_slashes function
This script will read lines from stdin end replace the ' with \' This is perfect for parsing text files and composing SQL queries.
#!/bin/bash
#filename: add_slashes.sh
read line
while [[ "$line" != "" ]]
do
echo "$line" | sed "s/'/\\\\'/g"
read line
done
Usage example: echo "Heherson's dog" | ./add_slashes.sh will produce "Heherson\'s dog"
#!/bin/bash
#filename: add_slashes.sh
read line
while [[ "$line" != "" ]]
do
echo "$line" | sed "s/'/\\\\'/g"
read line
done
Usage example: echo "Heherson's dog" | ./add_slashes.sh will produce "Heherson\'s dog"
1 Comments:
Nice one. Very useful. Thanks!
By Anonymous, at 8:41 AM
Post a Comment
<< Home