tr
deals with individual characters, it doesn't really deal with strings, though there is overlap.
you can replace multiple occurrences of a single character, with one occurrence( Replacing \\
with \
), an option it calls 'shrink' but you'd want the other way. In theory one could say that involves an individual character just as much, nevertheless, tr cannot do that, it has no option to give it a character and state how many times it should appear. It has that shrink character option but not a repeat character option.
You can use sed, you may find you have to use single quotes rather than double quotes
$ echo '\' | sed 's_\\_\\\\_g' \\
or sed 's/a/b/g' filename
syntax with sed with its s command, is sed "s/find/replace/"
and putting a g
modifier on the end will make sure it doesn't just stop at the first one, it replaces every occurrence. sed 's/find/replace/g'
Normally people use / You can use _ i.e. s_a_b_g
You don't put a / after the g.
As for \r\n
and \n
that sed line won't affect it. \r\n
is not stored with an actual backslash, it's stored with the binary for the ascii codes it represents. 13 for \r
and 10 for \n
look at an ascii table and you'd see that.