25.13 pushin: Squeeze Out Extra White SpaceIf you're viewing or printing a file with lines that are too long to read, you can use a program like fold (43.8 ) to fold the lines. Or, if there's lots of white space in each line - multiple spaces and/or TABs next to each other - you can use the script at the end of this article. The pushin script replaces series of spaces and/or TABs with a single space, "pushing in" each line as much as it can. It reads from files or standard input and writes to standard output. Here's an example of lines in a file that aren't too long (we can't print long lines in this book, anyway) but that do have a lot of white space. Imagine how pushin would help with longer lines: % Here's the script: #!/bin/sed -f s/[ ][ ]*/ /g Inside each pair of brackets, That file doesn't use a shell; 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 exec sed 's/[ ][ ]*/ /g' ${1+"$@"} It starts a shell, then
exec
replaces the shell with sed
(45.7
)
.
The - |
|