home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam    

UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 25.11 crush: A cat that Skips all Blank Lines Chapter 25
Showing What's in a File
Next: 25.13 pushin: Squeeze Out Extra White Space
 

25.12 Double Space, Triple Space ...

Here are handy scripts for printing drafts of files. They double-space or triple-space file(s) or standard input. For example:

% doublespace afile | lp


% prog | triplespace | lp

doublespace
triplespace
Here they are:

doublespace
   triplespace


#!/bin/sed -f   #!/bin/sed -f
G   G
   G

No, that isn't a typo: both scripts just use the sed command G (34.24 ) . The G command appends a newline and the contents of sed 's hold space, which will be empty in this script. The effect is to add a newline after every newline; two G s add two newlines.

That file doesn't even use a shell, so it's efficient; the kernel starts sed directly (45.3 ) and gives it the script itself as the input file expected with the -f option. If your UNIX can't execute files directly with #! , type in these versions instead:


doublespace
   triplespace

exec /bin/sed G ${1+"$@"}   exec /bin/sed 'G;G' ${1+"$@"}

They start a shell, then exec replaces the shell with sed (45.7 ) . The ${1+"$@"} works around a problem with argument handling (46.7 ) in some Bourne shells.

And now you know how to make quadruplespace , quintuplespace , ... :-) .

- JP


Previous: 25.11 crush: A cat that Skips all Blank Lines UNIX Power Tools Next: 25.13 pushin: Squeeze Out Extra White Space
25.11 crush: A cat that Skips all Blank Lines Book Index 25.13 pushin: Squeeze Out Extra White Space

The UNIX CD Bookshelf NavigationThe UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System










??????????????@Mail.ru