Active 3 years, 8 months ago. Menu. Note that since the shell will not do anything to i by itself, it needn't be quoted. i need to replace '/' forward slash with \\/(backward slash follwed by a forward slash) using sed command when the forward slash occurs as a first character in a file.. i need to replace '/' forward slash with \/(backward slash follwed by a forward slash) using sed command when the forward slash occurs as a first character in a file.. Here sed is used to replace the text foo with bar before it is echoed. Please Sign up or sign in to vote. How to delete all characters in one line after “]” with sed? Thanks for your response. But switch to: sed "s=old=new=" and now slash is just another character that need not be escaped. The hashes (#) are your chosen delimiter, a good alternative to the common forward slash (/) as your match is about this same character and this avoids the need for escaping. For example, you use it to introduce a double quote without ending the string: "hello \"Member 13199106\"" Which creates a string like this: As the forward slash (/) is special character in regular expressions, it has to be escaped with a backward slash (\). Hi, I have a string as d:abcshailxyz which is read from database and I have to create a log file (status.log) in this path so i get the string as path and append with the path the filename as path=path+filename; I am getting the following error:- However, sed can use any character as a delimiter. sed command to replace slash with backslash: stelmed: Slackware: 13: 08-19-2010 06:01 AM: forward slash being treated as escape character in shell? Sed is not needed if doing simple replacements in a scripts, bash can do that out of the box. In fact, it will automatically use the character following the s as a delimiter. And for the ToString variable: escape the '\' so that shell interpreter will expand to a single slash (in the third point below), when defining this variable, use single quotes so it is not expanded, and; expand (by double quoting) when using it within sed, to get the correct end result. Find and Replace with special characters, Finally, to top it off, you put a backslash escape in front of the forward-slash character that was supposed to be the middle delimiter for the "s///' Perl Double-q Operator, qq The "qq" operator replaces the double quote surrounding a string by its parentheses. AWK or SED to replace forward slash. B) if you want the ability to represent any arbitrary character in a string, some version of this feature is required. In JSON data (and many other systems such as C# for example) the back slash acts as an "escape" character, allowing you to enter "special characters" into a string by adding a '\' before the character or code. The essence of your question is how to replace a backslash (i.e. Issue the following linux command: sed … Stack Exchange network consists of 176 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share … If you use: sed "s/old/new/" then slash becomes a special character and you must escape any slashes that appear in either the old or new strings. share ... everything inside single quotes is treated literally by shell and as that passed to sed. Please test your idea on my file, as problem is not as obvious as it might seem to be - this is why I asked about it. Ask Question Asked 3 years, 8 months ago. Inside double quotes some characters are expanded, ... saying to replace all matches with the replacement. bash sed. The delimiter of choice is a forward slash (/), which is the most commonly used delimiter. sed search and replace with variable containing slash. I am trying to replace a string inside a text file with a variable. 2. Inside the Quote” s is used for separating every file rather than a single line long text, inside the forward-slash (/) you need to pass the string name which you want to remove, In between double forward-slash (//) need to provide a word which you want to keep. -i - By default, sed writes its output to the standard output. This question is for testing whether or not you are a human visitor and to prevent automated spam submissions. majormark, you missed the point of spirtle's post. Subject: [java-l] replace forward slash with double slash. But the names has a "\" in them like c:\New3\sample\Traffic Signal Preventative Vehicle\Pedestrian Signal Heads.xml.. Could anyone tell me how to … Hi Fellow Flow-ers, I'm not familar with the replace expression so need some help please. Sed special characters. In the end you need to provide a filename. Ask Question Asked 9 years, 4 months ago. Replace Forward Slash with sed. Code: mm dd ff /dev/name1 mm dd ff /dev/name2 mm dd ff /dev/name3 mm dd ff /dev/name4. s - The substitute command, probably the most used command in sed. Tried something like this but doesn't seem to work. This behavior does not apply to forward slash. i am trying to replace double backslash into single backslash.but its not happenuig correctly. One possibility is that rather than the -i flag, or additionally to the -i flag, you used sed's i (insert) command. It can be any character but usually the slash (/) character is used. Tried something like this but doesn't seem to work. /) by calling sed from find.To do that you have to double-escape the backslashes, because the string is going to be processed twice: once by the invocation of find and then a second time by the invocation of sed.This should give you the following: ... linux + sed - replace only the right most side char of string. If you want the replace some occurences of a URL in a file the sed command looks really ugly because you have to escape every slash "/" with a backslash "\" To make it look a lot cleaner you could just change the delimiter used by sed: Replace Forward Slash with sed i need to replace '/' forward slash with \/(backward slash follwed by a forward slash) using sed command when the forward slash occurs as a first character in a file.. Try escaping the '.' And sed comes handy when replacing strings in multiple files, using regex patterns if needed.. Bash string manipulation. in the sed regex, to be more accurate. Tried something like this but do | The UNIX and Linux Forums After using cat -A myfile it seems problem that those spaces are … With bash string manipulation it’s easy to replace strings in your scripts. i have a file live this. / / / - Delimiter character. What characters do I need to escape when using sed in a sh script , If you choose a character that has a special meaning in a BRE and you want to include it literally, you'll need three backslashes; I do not recommend this, as it may SED provides two special characters which are treated as commands. so change that delimiter character to something that is not used in either the old or new strings.