Here's a quick and simple command line drive text formatter using fmt.
Fmt binary file is part of fedora core utility package from GNU. Fmt reformats a a human readable file based on columnar value specified as argument. Fmt also supports splitting of long line, identation of first line, readjustment of file column width.
INSTALLATION
============
Core utils is installed by default fresh installation. However, if you had done a system cleanup, the package might have been uninstalled. Fmt can be installed to Fedora by installing core utils binary package using yum like so
# yum -y install coreutils
FMT USAGE
=========
# cat testfile.txt
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This is a long line of words that is useless for now.
This file is an example of human readable text file.
I am going to paste this file into my Linux SysAd blog!
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Uniform spacing is also supported by fmt linux command. Uniform spacing is one space between words and 2 spaces after sentences.
# fmt -u testfile.txt
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This is a long line of words that is useless for now. This file is an
example of human readable text file. I am going to paste this file into
my Linux SysAd blog!
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To change and adjust a standard column width or columnar line width to 5 would be like so
# fmt -w 5 testfile.txt
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This is a
long line of
words that
is useless
for now.
This file is
an example of
human readable
text file.
I am going
to paste this
file into my
Linux SysAd
blog!
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Now, let's modify our text file to give way for more sample fmt usage
# cat testfile.txt
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This is a long line of words that is useless for now.This file is an example of human readable text file.
I am going to paste this file into my Linux SysAd blog! This is a long line of words that is useless for now.This file is an example of human readable text file.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Using a crown-margin argument with fmt would be
# fmt -c testfile.txt
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This is a long line of words that is useless for now.This file is an
example of human readable text file.
I am going to paste this file into my Linux SysAd blog! This is a
long line of words that is useless for now.This file is an example
of human readable text file.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Using a tagged paragraph with fmt would be
# fmt -t testfile.txt
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This is a long line of words that is useless for now.This file is an
example of human readable text file.
I am going to paste this file into my Linux SysAd blog! This is a
long line of words that is useless for now.This file is an example of
human readable text file.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Altenatively, using standard input would be like
# cat testfile.txt | fmt -u -
# fmt -u - < testfile.txt
For more fmt info, man fmt
HTH
No comments:
Post a Comment
Thanks for the comment and for peeping into my blogspot. Hope you enjoy your reading them.
If you wish to receive posts updates, you can subscribe directly from this link:
http://feeds.feedburner.com/VertitosBlogspot
using any RSS reader or even Google Reader.
Again, appreciate your site visits.
Cheers then
VeRTiTO
Email: vertito@gmail.com