Posts

Showing posts from September 13, 2018

bash - add blank line to heredoc via variable

Image
Clash Royale CLAN TAG #URR8PPP up vote 0 down vote favorite If I am using this scenario in a script: #!/bin/bash addvline=$(if [ "$1" ]; then echo "$1"; echo; fi) cat << EOF this is the first line $addvline this is the last line EOF if $1 is emty I get a blank line. But how can I add a blank line after $1 for the case it is not emty? So in the case running the script like: bash script.sh hello I would get: this is the first line hello this is the last line I tried to achieve this with using a second echo in the if statement , but the newline does not get passed. bash variable cat here-document share | improve this question asked Oct 1 '17 at 16:23 nath 633 4 21 add a comment  |  up vote 0 down vote favorite If I am using this scenario in a script: #!/bin/bash addvline=$(if [ "$1" ]; then echo "$1"; echo; fi) cat << EOF this is the first line $addvline this is the ...

Linux: find files *.log in directory trees and write 10 last lines in each

Image
Clash Royale CLAN TAG #URR8PPP up vote 0 down vote favorite I need to find all files, that ends with .log in directory /var and all its trees-directories; and to write ten last lines of each of these *.log files cd /var sudo find -name '*.log' -print This command allows me to find these files. What I see is: ./log/auth.log ./log/Xorg.0.log .... ./log/apt/term.log .log/alternatives.log I've tried to use for var in sudo find -name '*.log'; do tail -n 10 $var; done to print the lines, but there was an error. So what command should I use in order to find files and print the lines? linux share | improve this question asked Oct 1 '17 at 16:40 Николай Журба 28 5 add a comment ...