How to send a plain txt file in a zip file via email in unix? The contents in the txt file should be word wrap.

  • Why the down vote? – Matteo Apr 17 '14 at 10:41
  • These are multiple questions: 1) how to word wrap a text file; 2) how to zip a plain txt file; 3) how to email a zip file as an attachment. What exactly have you tried for each and what is not working? – Anthon Apr 26 '14 at 6:06
  • @Matteo If you hover above the down vote arrow it says "This question does not show any research effort", I think that is applicable on each of the 3 questions asked. – Anthon Apr 26 '14 at 6:08

To wrap the text file you can use fold (see fold man page)

For example

fold -w 78 -s input.txt > wrapped.txt

will wrap your text to a maximum width of 78 characters. You can then use zip to compress it

zip wrapped.zip wrapped.txt 

and then send it per email with mail

mail -a wrapped.zip -s "Subject of the mail" recipient@example.com

(not all versions of mail support the -a option)


If your mail don't support -a option, do it with uuencode:

uuencode original_filename attachment_filename | mail -s "subject" recipient@xyz.com

for example (it's working in front of my eyes):

uuenconde ~/.netrc mynetrc.txt | mail -s "test" xyz@xyz.com

and I see the attachment as mynetrc.txt in the mail.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.