how to work with plain text
- Anmelden oder Registrieren um Kommentare zu schreiben
Hi friends
I have a big plain text (.txt) file that I would like to edit in the following ways:
1. after every "AM" or "PM, insert two "Enter"s (line breaks .. like if this were HTML)
2. before every "Received from", insert two "Enter"s
There might be a hundred to three hundred of these in the text file. Would you teach me how to do it automatically somehow?
M
Tested in Pluma, but other text editors should work similarly:
Use "find and replace" (Ctrl+H in Pluma). Make sure "Parse escape sequences" is checked.
- replace "AM" with "AM\n\n"
- replace "PM" with "MP\n\n"
- replace "Received from" with "\n\nReceived from"
That should work in Trisquel 7's terminal (but not necessarily with another implementation of sed than a recent GNU sed):
$ sed -i -e 's/[AP]M/&\n\n/g' -e 's/Received from/\n\n&/g' file.txt
Simple example using GNU Sed:
printf '01:00AM\nReceived from Ana\n02:00 PM\n03:00 AM\nReceived from
Bob\n' | sed 's/[AP]M/\0\n\n/g; s/Received from/\n\n\0/g'
For safety purposes, sed doesn't replace the contents of the file,
unless you pass `-i' to it.
2017-12-09T23:24:47+0100 name at domain wrote:
> Hi friends
>
> I have a big plain text (.txt) file that I would like to edit in the
> following ways:
>
> 1. after every "AM" or "PM, insert two "Enter"s (line breaks .. like
> if this were HTML)
>
> 2. before every "Received from", insert two "Enter"s
>
> There might be a hundred to three hundred of these in the text file.
> Would you teach me how to do it automatically somehow?
--
- https://libreplanet.org/wiki/User:Adfeno
- Palestrante e consultor sobre /software/ livre (não confundir com
gratis).
- "WhatsApp"? Ele não é livre. Por favor, veja formas de se comunicar
instantaneamente comigo no endereço abaixo.
- Contato: https://libreplanet.org/wiki/User:Adfeno#vCard
- Arquivos comuns aceitos (apenas sem DRM): Corel Draw, Microsoft
Office, MP3, MP4, WMA, WMV.
- Arquivos comuns aceitos e enviados: CSV, GNU Dia, GNU Emacs Org, GNU
GIMP, Inkscape SVG, JPG, LibreOffice (padrão ODF), OGG, OPUS, PDF
(apenas sem DRM), PNG, TXT, WEBM.
- Anmelden oder Registrieren um Kommentare zu schreiben