Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use sed to replace & with &

Tags:

unix

Hi I have a file and want to replace all & amp; with & using sed. Can you tell me how to use sed for this, as the following command did not worked for me.

sed 's/& amp;/&/g' BX-Books.csv > r1.txt

Here & and amp have no space between.

like image 747
user3454746 Avatar asked Mar 26 '14 15:03

user3454746


People also ask

Which sed command is used for replacement?

The Linux sed command is most commonly used for substituting text. It searches for the specified pattern in a file and replaces it with the wanted string. To replace text using sed , use the substitute command s and delimiters (in most cases, slashes - / ) for separating text fields.

How do you replace a variable in a file using sed?

For replacing a variable value using sed, we first need to understand how sed works and how we can replace a simple string in any file using sed. In this syntax, you just need to provide the string you want to replace at the old string and then the new string in the inverted commas.


1 Answers

Based on the title of the question, you need to escape &:

sed 's/\&amp/\&/g' BX-Books.csv > r1.txt
like image 157
Amit Verma Avatar answered Jan 03 '23 02:01

Amit Verma