The people on this forum have been a tremendous help! Thank you so much!
Here is my string
UEsDBBQAAAAIAKJBWEUdUIwScwwBAAB+AQAgAAAAQ29weV9vZl9kb2N1bWVudF9PY3QtMjQtMjAx\nNC5leGXsvXlcU0f0N5xAgICBRAVFRaVK3XfAigFFJYALGkSCKItWRMQNMVHrCl6ihGvc6lq1laKt\na11q3ZcgyKKouG+o2KJeDCoqCgpyn3Pm3ovY5X1\/zz\/
I'm trying to remove the \n and the \ from the above string.
I've tried:
tr ‘\n\r\\’ ‘ ‘
sed 's/\n//g;s;\\;;g'
And a few other variations, but I'm not successful in stripping everything. I can get the \ but not the n.
Does anyone see my error?
Try:
You want to remove a literal
\
followed by a literaln
. Consequently, the backslash has to be escaped in the first substitution. By contrast,s/\n//g
would remove newline characters.Use this with
tr
to delete (-d
) all\n
and\
:Test:
Output:
You could do simply like this. You don't need to have another substitution.
OR
Example:
Explanation:
Syntax of sed:
Command:
Splitted the above sed command like below for clarification.
s
- search and substitute.\\n\|\\
- Pattern .\\n
match a literal\n
OR\|
match a literal\
. So at first it matches all the\n
in the input string and then matches\
//
We have an empty replacement part, which means remove all the matched characters or replace the matched characters with an empty string.g
- Global modifier. It makes the match to happen globally. ie, if two or more\
symbols present on a single line, thissed 's/\\//' file
removes only the first\
for each line. But the global modifierg
forcessed
to match all the existing\
symbols.Through GNU sed,
Through Perl,