How to format grep statement?

I have a grep command that looks through the maillog and tells me how what source IPs are logging in to email.

The problem is that the output  has no <CR><LF>s in the file so it is a huge runon sentence. I am looking for the additional syntax that will at least give a <CR><LF> after every line, or a <br /> since I am looking at this file from a url link.  It would also be nice to have a blank line after every email address group.

This is my grep statement:
grep 'pop3-login' /var/log/maillog | grep ': Login: user' | sed -e 's/.*user=<//' -e 's/>.*rip=/ /' -e 's/, lip.*$//' | sort | uniq -c >/home/domain/public_html/email_logins.html

This is what I get:
12 xxx.228.235.254 1 xxx.134.196.144 524 xxx.14.122.184 523 xxx.78.29.0 5551 xxx.83.195.76 1061 xxx.110.64.230 302 xxx.197.96.69

This is what I would like to see:

12 xxx.228.235.254
1 xxx.134.196.144
524 xxx.14.122.184

523 xxx.78.29.1
5551 xxx.83.195.76

1061 xxx.110.64.230

302 xxx.197.96.69

Who is Participating?
ozoConnect With a Mentor Commented:
... | uniq -c | sed 'a<br>' >/home/domain/public_html/email_logins.html
after the uniq -c add
| awk ' { print $1,$2,$3,"\n"}' >> to your file
You can try to replace the carriage return and the line feed with a blank line.

perl -pi -e 's/\r\n/\n/g'

Open in new window

A proven path to a career in data science

At Springboard, we know how to get you a job in data science. With Springboard’s Data Science Career Track, you’ll master data science  with a curriculum built by industry experts. You’ll work on real projects, and get 1-on-1 mentorship from a data scientist.

did not notice that you were outputing to an html page.
from a security point of view do you really want to publish your email addresses?

write to a .txt file instead of html
ozo is right

given then fact hat sort and uniq work, your file is multi-line

several options there

1) html-ize the file
.... uniq -c | sed 's/$/<br>/' >> output file

2) have your web server print the file as text and not html. since any decent web server would do it automagically, i assume you have some kind of script that sends the file to the client. you'd need to instruct it to print a text/plain header and check for line endings if you expect to view it on windows. you can stick unixtodos or tofrodos in the pipe if you need to change line endings

3) you can print the output between <pre>...</pre>
jasgotAuthor Commented:
PERFECT! Thank you.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.