Re: inserting line breals
On 9/5/07, Nathan <debian@ucwv.edu> wrote:
> I've found a perl script on the 'Net that does a very good job of
> recursively searching a directory of sub-directories and files. I pipe
> the output to the 'mail' program and email it to myself. However it
> would help the readability of the text if I could add an extra line
> break (carriage return) to each existing line break. Effectively I
> would to double-space it.
>
> I am not a perl guru in any shape or form. Can anyone offer suggestions
> on the best way to go about this? Thanks.
The following one-liner should do it (it works for me):
perl -pe '$_ .= "\n"' <filename>
You could also do the following:
perl -pi.bak -e '$_ .= "\n"' <filename>
<filename> will now contain the double-spaced text, and <filename>.bak
will contain the original file.
Here's how it works:
"-p" uses an implicit
while(<>)
{
# foo
print $_;
}
with "# foo" replaced by your provided script. "-e" specifies that
the next string is the script to run. "-i.bak" says to do in-line
replacement, moving the original to a file with ".bak" as the
extension. You could use any extension you like here.
Since $_ will be printed automatically, we append (".=") a newline to it.
--
Michael A. Marsh
http://www.umiacs.umd.edu/~mmarsh
http://mamarsh.blogspot.com
http://36pints.blogspot.com
Reply to: