2

I have output in bash that I would like to format. Right now my output looks like this:

1scom.net 1
1stservicemortgage.com 1
263.net 1
263.sina.com 1
2sahm.org 1
abac.com 1
abbotsleigh.nsw.edu.au 1
abc.mre.gov.br 1
ableland.freeserve.co.uk 1
academicplanet.com 1
access-k12.org 1
acconnect.com 1
acconnect.com 1
accountingbureau.co.uk 1
acm.org 1
acsalaska.net 1
adam.com.au 1
ada.state.oh.us 1
adelphia.net 1
adelphia.net 1
adelphia.net 1
adelphia.net 1
adelphia.net 1
adelphia.net 1
adelphia.net 1
adelphia.net 1
adelphia.net 1
adelphia.net 1
adelphia.net 1
adelphia.net 1
aecom.yu.edu 1
aecon.com 1
aetna.com 1
agedwards.com 1
ahml.info 1

The problem with this is none of the numbers on the right line up. I would like them to look like this:

1scom.net                 1
1stservicemortgage.com    1
263.net                   1
263.sina.com              1
2sahm.org                 1

Would there be anyway to make them look like this without knowing exactly how long the longest domain is? Any help would be greatly appreciated!

The code that outputted this is:

grep -E -o -r "\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,6}\b" $ARCHIVE | sed 's/.*@//' | uniq -ci | sort | sed 's/^ *//g' | awk ' { t = $1; $1 = $2; $2 = t; print; } ' > temp2
7
  • 2
    Pipe to column -t. Commented Apr 21, 2015 at 4:00
  • 1
    Yup. Also there's no reason for the sed in there to remove leading spaces. The awk command does that for you by default (when you play with fields). Commented Apr 21, 2015 at 4:04
  • You can also reduce the noise in the awk component. ... | uniq -ci | awk '{print $2,$1}' | column -t In fact, if you want to provide an example of your source data, I'm sure we can improve the whole command line. What's inside $ARCHIVE? Oh and also, there are many TLDs which will not fit inside \.[A-Za-z]{2,6}. Commented Apr 21, 2015 at 4:09
  • There are many email text files inside of ARCHIVE. How would I capture all domains in a regex @ghoti? Commented Apr 21, 2015 at 4:14
  • 1
    Waitasec. Is this the same question as this other one, and this other one as well? Please don't abandon your old questions. Either clarify them to improve them so they can be answered, or delete them. If you have better ways of expressing your question, put them IN YOUR QUESTION, don't just ask a new one. Commented Apr 21, 2015 at 4:15

1 Answer 1

2

ALIGNMENT:

Just use cat with column command and thats it:

cat /path/to/your/file | column -t

For more details on column command refer http://manpages.ubuntu.com/manpages/natty/man1/column.1.html

EDITED:

View file in terminal:

column -t < /path/to/your/file

(as noted by anishsane)

Export to a file:

column -t < /path/to/your/file > /output/file

Sign up to request clarification or add additional context in comments.

1 Comment

This is UUOC. column -t < /path/to/your/file works too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.