Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
    
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
    
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 3:09
up vote 8 down vote accepted
tail -f file | sed 's/\\n/\n/g'
share|improve this answer
    
tail -f file | sed 's/\\n/\n/g' – Vi. Mar 26 '10 at 2:54
    
Thank you. Fixed. – Dennis Williamson Mar 26 '10 at 3:54
1  
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' – Jon z Dec 20 '11 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 '15 at 14:17
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 8 '15 at 17:19
tail -1 file | awk '{gsub(/\\n/,"")}1'
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.