LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-21-2005, 08:48 AM   #1
farmerjoe
Member
 
Registered: Oct 2004
Location: Texas
Distribution: Ubuntu - Home, RHEL4 - Server
Posts: 96

Rep: Reputation: 15
Help Deleting a Backslash! Am i an idiot?


I swear, i have been trying to do this for hours, but can't seem to get it right.

I need to delete a \ (escape character) in a string. It is being put there automatically in a PHP form as an escape character to escape apostrophies, but I desperately need a way (in bash) to delete it! I've tried tr and sed, but my knowledge is limited. Please help!

Here is an example:
Problem: Farmerjoe\'s idiocracy is causing him heartache!
Solution: Farmerjoe's idiocracy is causing him heartache!

Thanks!,
farmerjoe
 
Old 03-21-2005, 09:37 AM   #2
YetAnotherDave
Member
 
Registered: Feb 2005
Posts: 95

Rep: Reputation: 17
How's this?

Code:
#! /bin/bash
X="Farmerjoe\'s idiocracy is causing him heartache!"
echo  $X
echo  $X | sed -e 's/\\//g'
- Dave
 
Old 03-21-2005, 10:12 AM   #3
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
or
Code:
str="it\\'s a string\with\backspace\"
echo $str | tr -d '\\\'
or in PHP
PHP Code:
$str "it\\'s a string\\with\\backspace";
echo 
stripslashes($str); 

Last edited by keefaz; 03-21-2005 at 10:13 AM.
 
Old 03-21-2005, 11:03 AM   #4
farmerjoe
Member
 
Registered: Oct 2004
Location: Texas
Distribution: Ubuntu - Home, RHEL4 - Server
Posts: 96

Original Poster
Rep: Reputation: 15
The PHP method was perfect keefaz. Unfortunately i was not able to get the tr or sed methods to perform as desired. I had previously tried both before posting the question on the forum. But thanks everyone for your help and suggestions! You guys are great!

-farmerjoe
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
sed command to replace slash with backslash stelmed Slackware 13 08-19-2010 05:01 AM
backslash input in script esasse Linux - Newbie 6 02-17-2005 06:55 AM
Trailing Backslash problem duerra Linux - Newbie 6 01-28-2004 12:58 PM
Backslash in URL Cynthia Blue Linux - Newbie 17 08-18-2003 07:36 AM
Apache: Need backslash to indicate directory? kipbenson4 Linux - Software 2 08-12-2003 09:13 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:38 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration