help! Script or command needed to replace text in a file.
I am relatively new to linux. I need to replace occurences of chars (", ', `, and \) with (\", \', \`, and \\). I do not know of a linux function that will do that, only a PHP one which is str_replace. I need these characters changed to the new ones because PostgreSQL and MySQL dont recognize these characters. Any help i can get would be great. I assume i will have to use sed or gawk but i am completely unfamilier with how those work.
Thanks, -farmerjoe |
ok, this is REALLY quick and dirty, but it should actually get the work done. It is not failsafe by any means, and will happily change \" to \\\" (first \ to \\, then " to \") So the first one, which turns the \ into \\ must be run first. You better not use any of the characters for anything else, or you need a more advanced solution :-) (which i dont have time to try and think up right now)
perl -pi -e 's/\\/\\\\/g' file perl -pi -e 's/"/\\"/g' file perl -pi -e "s/\'/\\\'/g" file perl -pi -e 's/\`/\\\`/g' file |
Thanks! that should do the trick! i was having a lot trouble changing the ' character using sed alone. perl worked nicely.
-farmerjoe |
All times are GMT -5. The time now is 10:51 AM. |