tags:

views:

52

answers:

3

I ended up with a huge, single line string literal (don't ask me how) where everything is escaped (mostly), including new lines and double quotes. Problem is, I want the original string. The string is huge so I'm not even sure how to begin. Here's what I have:

"This\n is \"nice\",\nain\'t it?"

This is what I want:

This
 is "nice",
ain't it?

Again, the problem is that other shell sensitive stuff is not escaped (like $, or !), and that the string is couple of megabytes.

+1  A: 

Sed's your buddy.

cat huge | sed -e 's/\\n/\  << yes,hit the enter key here, the \ capture the newline
/g' -e 's/\\"/"/g' -e 's/\\'/'/g' ... > file
Will Hartung
+1  A: 

Python one-liner:

open("unescaped.txt", "w").write(eval(open("string.txt").read()))

You should have python on most linux installs.

tzaman
+2  A: 
string="This\n is \"nice\",\nain\'t it?"
string=$(printf "$string")

Or

string=$(<file.txt)
string=$(printf "$string")
Dennis Williamson
Won't work because the string is not shell escaped and is full of characters like '$' and '!' that will mess up the assignment to a variable. (The first thing I tried, by the way).
Lajos Nagy