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.

3
  • 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, 2010 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, 2010 at 3:09
  • Tip: if you would like colours and stuff, try: grc --colour=on tail -f file | sed 's/\\n/\n░░░░/g
    – Flimm
    Feb 8, 2023 at 18:14

2 Answers 2

33
tail -f file | sed 's/\\n/\n/g'
4
  • 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, 2011 at 18:46
  • Does anyone know of a way to achieve the same thing for multitail? Here's a question: unix.stackexchange.com/questions/239774/…
    – fraxture
    Oct 30, 2015 at 14:17
  • I cannot get that to work as an alias in my .bashrc
    – Kdansky
    Dec 8, 2015 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'; } Dec 8, 2015 at 17:19
0
tail -1 file | awk '{gsub(/\\n/,"")}1'

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .