I ask this question after trying all codes shared in the site about this without success,
I have a file that contains a very long text, all the text is in the first line only
I want to append long line with symbols to the end of this file, and my line look like this:
[{\n"code":"final .net.wifi.WifiManager wifi \u003d\n "typeName":"","palette":"9","type":" ","spec":"Enable WiFi"}]'
I want to append this line that contains symbols such as \n
and [{]"...
. to an existing file in the end of first line.
As your line is very complex and contains many escape characters I'd suggest using printf "%q" that some shells such as Bash support. You can use the following short script:
#!/usr/bin/env bash
read -r
printf "%q\n" "$REPLY"
Run it and paste your line:
$ ./printf-q.sh
[{\n"code":"final .net.wifi.WifiManager wifi \u003d\n "typeName":"","palette":"9","type":" ","spec":"Enable WiFi"}]'
\[\{\\n\"code\":\"final\ .net.wifi.WifiManager\ wifi\ \\u003d\\n\ \"typeName\":\"\"\,\"palette\":\"9\"\,\"type\":\"\ \"\,\"spec\":\"Enable\ WiFi\"\}\]\'
The last line is showed in the form you can use in shell without adding extra escape characters like that:
$ echo \[\{\\n\"code\":\"final\ .net.wifi.WifiManager\ wifi\ \\u003d\\n\ \"typeName\":\"\"\,\"palette\":\"9\"\,\"type\":\"\ \"\,\"spec\":\"Enable\ WiFi\"\}\]\' >> FILE
$ cat FILE
[{\n"code":"final .net.wifi.WifiManager wifi \u003d\n "typeName":"","palette":"9","type":" ","spec":"Enable WiFi"}]'
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments