Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Mail logs are incredibly difficult to read... how could I ouput a blank line between each line printed on the command line. For example say, i'm grep-ing the log. That way multiple wrapped lines aren't being confused.

share|improve this question

5 Answers 5

up vote 13 down vote accepted

sed G

G is not often used, but is nice for this purpose. sed maintains two buffer spaces: the “pattern space” and the “hold space”. The lines processed by sed usually flow through the pattern space as various commands operate on its contents (s///, p, etc.); the hold space starts out empty and is only used by some commands.

The G command appends a newline and the contents of the hold space to the pattern space. The above sed program never puts anything in the hold space, so G effectively appends just a newline to every line that is processed.

share|improve this answer
2  
The -e isn't necessary. piping whatever | sed G ought to do the trick. –  frabjous Oct 15 '10 at 2:25
1  
Great answer! I love the simplicity of it. –  Steven D Oct 15 '10 at 5:06
    
@frabjous: Right, might as well leave off the -e since there we only need a single command argument. –  Chris Johnsen Oct 15 '10 at 18:49

Use sed and replace the whole line by itself plus one extra newline character:

grep foo /var/log/maillog | sed -e "s/^.*$/&1\n/"
share|improve this answer
2  
A slightly simpler sed substitution would be 's/$/\n/', although @Chris Johnsen's 'G' command is even simpler. –  camh Oct 15 '10 at 5:05

Use awk to add an extra newline. This also lets you filter out things you don't want.

awk '{print $0,"\n"}' | less
share|improve this answer

Is this what you are after?

grep SPAM mail.log | while read -r line; do echo; echo $line; done

share|improve this answer
    
You will probably want to use read -r to avoid treating backslash characters as special. –  Chris Johnsen Oct 15 '10 at 1:57

If it's for more than just have look, I prefer to send them to a text file and open with a text editor so you can set the lines to wrap or not and do searches easily... and delete the unwanted lines and so on without having to type a lot of commands.

cat file.log > log.txt and gedit log.txt or a terminal editor like nano

Edit: or cp file.log log.txt wich is of course easier and faster... thanks to KeithB comment

share|improve this answer
1  
Why cat and not cp? –  KeithB Oct 15 '10 at 13:21
    
sure cp would be easier and faster!... lol - I was reading the other answers dealing with grep and awk so I wrote it the cat way but I'm correcting that, thanks –  laurent Oct 15 '10 at 13:49

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.