20

I have a file that I am trying to read by using tail -f. I was wondering if there was a way to have the terminal output an actual line break instead of the \n character.

GSto
  • 391
  • 1
  • 3
  • 8
  • 1
    As a rule, tail -f will display line breaks as line breaks. You may have an issue with your console settings, if that's what you're seeing. – Jon Lasser Mar 25 '10 at 21:50
  • 1
    Or he's tailing a file which actually has a literal \n in it. Maybe line breaks were converted to a literal "\n" before being written to a file. – Josh Mar 26 '10 at 03:09
  • Tip: if you would like colours and stuff, try: `grc --colour=on tail -f file | sed 's/\\n/\n░░░░/g` – Flimm Feb 08 '23 at 18:14

2 Answers2

33
tail -f file | sed 's/\\n/\n/g'
Dennis Williamson
  • 62,149
  • 16
  • 116
  • 151
  • 2
    I would like to add that I found I needed to actually physically enter a line break in my sed command after the back-slash in order to make this work, like so: `~$ tail -f /var/log/apache2/error_log | sed 's/\\n/\ > /g'` – jrz Dec 20 '11 at 18:46
  • Does anyone know of a way to achieve the same thing for multitail? Here's a question: https://unix.stackexchange.com/questions/239774/how-can-i-display-n-as-new-lines-in-multitail – fraxture Oct 30 '15 at 14:17
  • I cannot get that to work as an alias in my .bashrc – Kdansky Dec 08 '15 at 14:14
  • 1
    @Kdansky: You didn't show how you defined the alias or what kind of problem you're having so I can only guess. One problem you may be having is with quoting. An extra backslash may help: `alias forward="tail -f file | sed 's/\\\n/\n/g'"`. If you want to be able to specify the filename as an argument, you should use a function instead of an alias: `forward () { tail -f "$@" | sed 's/\\n/\n/g'; }` – Dennis Williamson Dec 08 '15 at 17:19
0
tail -1 file | awk '{gsub(/\\n/,"")}1'
user37841
  • 341
  • 1
  • 2