Reputation: 99
I have a file that is formatted like this:
> ABC
1
2
> DEF
3
4
I would like to use tr to replace each >
with 4 carriage returns, so it looks like:
ABC
1
2
DEF
3
4
I tried the following in the Terminal: cat input | tr ">" "\n\n\n\n" > output
However, this only adds one carriage return between the two blocks of data, like this:
ABC
1
2
DEF
3
4
How can I get it to recognize the multiple carriage returns? Thanks!
Upvotes: 2
Views: 2158
Reputation: 50328
tl;dr
tr is the wrong tool for the job; try something else (like sed)
tr (text replace) only does 1:1 replacement - so it will only replace one character, with another, at a time. I think your current command replaces > with /n, >> with /n/n, >>> with /n/n/n and >>>> with /n/n/n/n.
try using sed instead, probably something like this (untested!):
cat input | sed $'s/>/\\\n\\\n\\\n\\\n/g' > output
Upvotes: 2