Web Development

Reformatting Text Using Pattern Matching

By Julius C. Duque, April 01, 2004

Whenever I write documents, I spend a considerable amount of time just reformatting lines of text so that they fit within a 70-character-wide column. I do this because I don't like reading long lines that wrap across the screen.

April, 2004: Reformatting Text Using Pattern Matching

1 ./pretty --width=64 --both --newline --indent=4 gettysburg.txt
2 ./pretty -w=64 -b -n -i=4 gettysburg.txt
3 ./pretty -w 64 -b -n -i 4 gettysburg.txt
4 cat gettysburg.txt | ./pretty --width=64 --both --newline -i=4
1 Four score and seven years ago our fathers brought forth on
2 this continent, a new nation, conceived in Liberty, and
3 dedicated to the proposition that all men are created equal.
4
5 Now we are engaged in a great civil war, testing whether
6 that nation, or any nation so conceived and so dedicated, can
7 long endure. We are met on a great battle-field of that war. We
8 have come to dedicate a portion of that field, as a final
9 resting place for those who here gave their lives that that
10 nation might live. It is altogether fitting and proper that we
11 should do this.

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task.
However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

This month's Dr. Dobb's Journal

This month,
Dr. Dobb's Journal is devoted to mobile programming. We introduce you to Apple's new Swift programming language, discuss the perils of being the third-most-popular mobile platform, revisit SQLite on Android
, and much more!