Register
It is currently Sun Dec 21, 2014 4:57 am

Script to eliminate carriage return


All times are UTC - 6 hours


Post new topic Reply to topic  [ 3 posts ] 
Author Message
 PostPosted: Sat Jul 23, 2011 2:37 am   

Joined: Mon Apr 24, 2006 2:39 pm
Posts: 30
Location: Villahermosa
This is a classic issue where emails and usenet format text to a set ammount of characters and insert a jump line or carriage return.
I want a script that can eliminate unnecesary carriage return and just respect the paragraph jumplines but eliminates the artificial ones.
I guess sed or awk should be the ideal tools but I am not that experience working with regex and awk.

For example:
Quote:
Hola compañeros: recientemente recibí la Olidata y me encuentro con que no
tiene la versión 88 sino Sugar on a Stick (Mirabelle) Fedora 13 (Goddard)
que paree ser un simulador de la imagen (no entiendo bien)

Entre los problemas mayores que encuentro es que no se ven las mallas, no se
pueden leer los PDF y muchos programas no se ven por la configuración que
tienen.


To:
Quote:
Hola compañeros: recientemente recibí la Olidata y me encuentro con que notiene la versión 88 sino Sugar on a Stick (Mirabelle) Fedora 13 (Goddard) que paree ser un simulador de la imagen (no entiendo bien)

Entre los problemas mayores que encuentro es que no se ven las mallas, no se pueden leer los PDF y muchos programas no se ven por la configuración que tienen.


Top
 Profile WWW ICQ YIM  
 PostPosted: Sat Jul 23, 2011 9:06 am   
User avatar

Joined: Wed Jun 08, 2011 8:27 am
Posts: 189
Location: outer Shpongolia
Something like this?

Code:
awk '! NF { printf("\n\n") } { printf(NF ? "%s " : "%s", $0) } END { printf("\n") }' file
awk '! NF { printf("\n\n") } { NF ? ORS = FS : ORS = "" } 1; END { printf("\n") }' file
awk 'NF { l = l s $0; s = FS; next } l { print l; s = l = "" } 1; END { if (l) print l }' file


Top
 Profile  
 PostPosted: Sat Jul 23, 2011 2:53 pm   
User avatar

Joined: Tue Apr 27, 2010 2:28 pm
Posts: 172
Location: Czech Republic
You can use perl as well:
Code:
perl -pe 's/\n/ /;$_="\n\n"if" "eq$_'

This simple one-liner adds a space at the end of each line. If you do not want it, you have to type more:
Quote:
perl -pe 'chomp;if($_){print" "if$f++}else{print"\n\n";$f=0}'


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP