using perl to fix text formatting issues

These commands could be executed within a text document using the vi editor, in fact, that's what I was doing repeatedly, and finally modified the sed strings to work with command line perl and then incorporated them into a clean up script. This script can be run on the same text multiple times without causing any harm. The first line: #!/bin/bash - is the shell directive, all commands in this file should be execute as in a bash shell. The 2nd line is an echo statement that displays on the screen to let you know it ran. The first two perl lines remove any bracketed information in the text, such as for foot notes. The other lines add and adjust spaces after specific punctuation.

############################################################################################### #!/bin/bash echo "remove bracketed footnotes, fixed commas and semicolon spacing" perl -pi -e 's/\[.\]//g' *.txt # remove bracketed text such as a footnote perl -pi -e 's/\[..\]//g' *.txt # remove bracketed text such as a footnote perl -pi -e 's/,/, /g' *.txt # adds a space after a comma perl -pi -e 's/, /, /g' *.txt # removes any extra spaces after a comma after adding a space perl -pi -e 's/;/; /g' *.txt # adds a space after a semicolon perl -pi -e 's/:/: /g' *.txt # adds a space after a colon perl -pi -e 's$\.$. $g' *.txt # adds a space after a period perl -pi -e 's/?/? /g' *.txt # adds a space after a question mark ############################################################################################### # the following sed and perl string replace all the lines below, used brackets for upper-case ############################################################################################### sed -i 's/[A-Z]/ /g # add space before uppercase letter perl -pi -e 's/ / /g # change two spaces to one ############################################################################################### # perl -pi -e 's/A/A /g' *.txt # adds a space after an uppercase A # perl -pi -e 's/A /A /g' *.txt # removes any extra spaces before an uppercase A # perl -pi -e 's/T/T /g' *.txt # adds a space after an uppercase T # perl -pi -e 's/T /T /g' *.txt # removes any extra spaces before an uppercase T # perl -pi -e 's/W/W /g' *.txt # adds a space after an uppercase W # perl -pi -e 's/W /W /g' *.txt # removes any extra spaces before an uppercase W # perl -pi -e 's/Y/Y /g' *.txt # adds a space after an uppercase Y # perl -pi -e 's/Y /Y /g' *.txt # removes any extra spaces before an uppercase Y ############################################################################################### # need to figure out bracket in perl: perl -pi -e 's/(.*)/<img src=\"$1\"><br>$1<hr>/' ###############################################################################################


Simply Linux: Basics Linux Tackles Microsoft Using BASH on Windows 10
Practical Suggestions for Microsoft Windows
 Full Size Jeep Buyer's Guide
12 hour Video Course by john:
The Art of Linux System Administration
published by O'Reilly Media
Study Guide for the LPIC-2 Certification Exams
search for:
on the internet, or:
JohnMeister.com-fotos
LinuxMeister-Linux
BibleTech- Bible overview

overview of mankind's history
Biblical history:
"Promises and Prophets"

Wagoneers

FULL SIZE JEEPS

JeepMeister
"Jeep is America's
only real sports car."
-Enzo Ferrari


MeisterTech
Diesels +

One Page Overview of Linux Commands

click for an image of the 5 essential Linux commands

An Intro to Linux
AMSOIL product guide,
or, AMSOIL web, or 1-800-956-5695,
use customer #283461

Amsoil dealer since 1983
purchase AMSOIL
at Midway Auto on SR9 in Snohomish,
or at Northland Diesel in Bellingham, WA


SJ - 1962-1991

XJ - 1984-2001

WJ - 1999-2004

KJ - 2002-2007

WK - 2005-2010

Find the recommended
AMSOIL synthetics
for your Jeep

CJ-10A - 1984-1986

Jeepsters

MJ - 1984-1992

Willys - 1946-1965

Other Jeeps (FC)