skip to Main Content

I want to be able to print out my logs with extra new lines.

This is what the logs look like

2021/04/29 12:30:19 [error] 30098#30098: *443497 FastCGI sent in stderr: "PHP message: PHP Warning:  Use of undefined constant last_login - assumed 'last_login' (this will throw an Error in a future version of PHP) in /var/www/html/app/addons/my_changes/func.php on line 9PHP message: PHP Notice:  Array to string conversion in /var/www/html/app/addons/my_changes/func.php on line 9" while reading response header from upstream, client: 172.70.34.13, server: www.example.com, request: "GET /Total-9-Abrasive-Grinding-Disc-TAC2232301 HTTP/1.1", upstream: "fastcgi://unix:/var/run/php/php7.3-fpm.sock:", host: "www.example.com"
2021/04/29 12:30:24 [error] 30098#30098: *443501 FastCGI sent in stderr: "PHP message: PHP Warning:  Use of undefined constant last_login - assumed 'last_login' (this will throw an Error in a future version of PHP) in /var/www/html/app/addons/my_changes/func.php on line 9PHP message: PHP Notice:  Array to string conversion in /var/www/html/app/addons/my_changes/func.php on line 9" while reading response header from upstream, client: 172.70.34.73, server: www.example.com, request: "GET /Kitchen-and-Dinning/Tableware/Glass/Luminarc-Tumbler-6pcs-Scotland-33cl-N0763?sort=rating&order=DESC&limit=100 HTTP/1.1", upstream: "fastcgi://unix:/var/run/php/php7.3-fpm.sock:", host: "www.example.com"
2021/04/29 12:30:25 [error] 30098#30098: *443503 FastCGI sent in stderr: "PHP message: PHP Warning:  Use of undefined constant last_login - assumed 'last_login' (this will throw an Error in a future version of PHP) in /var/www/html/app/addons/my_changes/func.php on line 9PHP message: PHP Notice:  Array to string conversion in /var/www/html/app/addons/my_changes/func.php on line 9" while reading response header from upstream, client: 141.101.105.129, server: www.example.com, request: "GET /index.php?dispatch=product_features.add_product&product_id=9534&redirect_url=index.php%3Ffeatures_hash=1-877%26sort_by=popularity%26sort_order=desc%26layout=short_list%26dispatch=categories.view%26category_id=30%26page=15 HTTP/1.1", upstream: "fastcgi://unix:/var/run/php/php7.3-fpm.sock:", host: "www.example.com"

They look much cluttered in the terminal and although there is a newline, I want to add 1 more newline to make it more readable.

I tried using

tail -n 10 /var/log/nginx/example.com_error.log | sed 's/n/nn/g'

and

tail -n 10 /var/log/nginx/example.com_error.log | tr 'n' 'nn'

to no avail.

2

Answers


  1. $ means end-of-line in sed.

    $: cat file
    12312312
    123123123
    123123123
    123123123
    
    $: sed 's/$/n/' file
    12312312
    
    123123123
    
    123123123
    
    123123123
    
    Login or Signup to reply.
  2. $ printf 'foonbarn' | pr -td
    foo
    
    bar
    
    $
    

    Not entirely certain about portability, but the open group specs (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/pr.html#tag_20_93_01) state:

    -d
    Produce output that is double-spaced; append an extra <newline> following every <newline> found in the input.
    

    and

    -t
    Write neither the five-line identifying header nor the five-line trailer usually supplied for each page. Quit writing after the last line of each file without spacing to the end of the page
    

    so it’s pretty standard.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search