0

when i run this command..

tail -10 /var/log/httpd/error_log | tr "\n" "----"

tr replaces new lines with nothing rather than the indent of

----

i am using tr because perhaps it might be faster than sed.
but if there are no solutions.. i wouldn't mind using sed.

ultimately i am trying to replace new lines with

</br>
  • `tr` takes 2 sets of characters as arguments and replaces each occurence of the 1st set by the matching occurence on the 2nd set. For instance, `tr "abc" "xyz"` will replace a with x, b with y and c with z. Thus it wont be able to do the job in your case as you want to replace 1 character with several – Aserre Jun 12 '14 at 08:07
  • 1
    Use this: `sed ':a; N; s/\n/<\/br>/g; $!ba;' yourfile` – sat Jun 12 '14 at 08:09
  • `tail -10 /var/log/httpd/error_log | sed -e ':a; N; s/\n/\<\/br\>/'` – stanleyxu2005 Jun 12 '14 at 08:12
  • @sat, excellent answer. i would choose this as the answer but the answer has been marked as duplicate. the truth is it is not a duplicate question given the lack of knowledge that tr requires equal amount of characters for replacement – Sümer Kolçak Jun 12 '14 at 08:18
  • 1
    The fact is that the question cannot be answered using `tr`. Since you mentioned that you can use `sed`, it already has answers. – devnull Jun 12 '14 at 09:45
  • 1
    @devnull, the fact that it can not be done via 'tr' becomes an apparent answer that benefits the internet. – Sümer Kolçak Jun 12 '14 at 10:48
  • If you search this site, you would find numerous posts mentioning what `tr` does. – devnull Jun 12 '14 at 11:33

0 Answers0