I'm in the process of being forward-thinking and finally converting my site's db to UTF-8. I've already done the UTF-8 conversion (on a copy for testing) and now I want to go through and convert html entities to their actual characters.
I ran an entity decode on a mysqldump file but realized that entites for apostrophes and quotes in the file were converted to ' and " without the slashes, thereby screwing up mysql's field delimiting.
So I had the bright idea of searching for and replacing , say, each apostrophe html entity with a backslash and the entity. That way when I ran the html enity decode I'd end up with a properly escaped apostrophe.
I did
and it didn't add the backslash.. (I'm using apos here because the board is interpreting the entities)
I then doubled the backslash to escape it, like this:
However that gave me this in the new file \aposapos
How do I insert a backslah with sed?
Thanks,
Last edited by Scrutinizer; 12-04-2013 at 02:33 PM..
Reason: code tags
Do you mean something like:
If not, please provide input and output samples
For quoting quotes I am more used to
that even works with a C-shell.
Rule: prefer the safer 'ticks' over the "quotes";
replace each ' within 'ticks' with '\''
so it becomes a \' escaped by the shell (outside the 'ticks').
I'll clarify my question. I found it difficult to post because my searches included html entities and the forum software was translating them into characters. The apos was just meant to represent the entity in the question.
Ok, so...
Search phrase: & #39; <--obviously without the space.
Replace phrase: \& #39; <-- backslash & #39; again obviously without the space.
Ahah. & has a special meaning to sed -- on the right side, it means 'the pattern that was matched', which is why you end up getting it twice. So you need to escape it, too, to have it taken literally.
HI All
Im trying to come up with an approach to finding a string, using a portion of that string to insert it on lines starting with the value "GOTO" appending to end of line after removing PT's ( See example below! )
EXAMPLE:
1. I would like to search for the line that starts with "TLAXIS/"... (7 Replies)
Hi I was wondering if anyone new of a solution to this problem? I need to copy a time stamp that is on a line of .text in a text file into multiple positions on the same line.
I need to insert the time stamp on the same line between every occurance of the text ".pdf_.html" right after the... (9 Replies)
Hi all,
I have a file like this
Q8N302
21-84
Q8N157
15-45
Q99996
167-201
202-251
269-318
I want to insert a character or space if the line starts with a number and I used the command
sed 's/^/#/'
But in the output file, when it inserts this character, first digit in the number is... (2 Replies)
Hi,
I have a xml file (Config.xml) with following entry
<Date="" Node1="50" Groups="20">
Now I want to use sed to insert/update the Date field with the latest date say - 20120711. I can't use a simple replace command becuase the Date field could be blank ("") or sometimes could have value in... (9 Replies)
hi I am trying to use SED to replace the line matching a pattern using the command
sed 'pattern c\
new line
' <file1 >file 2
I got two questions
1. how do I insert a blank space at the beginning of new line?
2. how do I use this command to execute multiple command using the -e... (5 Replies)
I have done this sed command to insert one line after a specific string is found:
sed '/patternstring/ a\
new line string' file1
But how do I insert two lines? This is not possible:
sed '/patternstring/ a\
new line string \a
new line string 2' file1 (2 Replies)
My txt file consists of records with 6 numbers followed by 3 characters.
Is there a simple “sed” which will insert a | separator between the 6th and 7th position ?
Many thanks (3 Replies)
Hello all
i have big test file that has allot of structure text something like this :
<foo1 *.html>
<blah action>
somthing 1
somthing 2
</blah>
</foo1 >
now i will like to insert 2 more lines of text below the <blah action>
so it will be like :
<foo1... (1 Reply)
Hello. Trying to insert text at line 1 and after last line of file. I have searched posts but nothing seems to work. I keep getting extra characters error or nothing gets inserted into the file.
#!/bin/sh
touch textfile.txt
sed 'i\
Add this line before every line with WORD' textfile.txt
... (5 Replies)