Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Mailing Lists -> Oracle-L -> Re: joining word/ lines in a file

Re: joining word/ lines in a file

From: Steven Lembark <lembark_at_wrkhors.com>
Date: Tue, 28 May 2002 21:58:22 -0800
Message-ID: <F001.0046D92C.20020528215822@fatcity.com>

> If isn't perfect. An 'and' at the end of the line will be joined with
> the beginning of the next line, which is not right.

Don't strip the newlines, replace them with white space:

    perl -e 'undef $/; ($a=<ARGV>) =~ s/\n+/ /g; print $a' \

        [file [file...]] [<file]

i.e., slurp the input whole, replace any sequence of one-or- more newlines with a single space and spit out the result.

If the input doesn't have multiple spaces in the fields you might get better result to strip newlines followed by whitespace:

    ... ~= s/\n\s+/ /g

will take any single newline and all the whitespace that follows it and replace the result with a space.

If none of the data fields being hacked have spaces in them a further:

    $a =~ s/ +/ /g

will replace one or more literal spaces with a single space to clean things up a bit:

    ... -e 'undef $/;($a=<ARGV>) =~ s/\n+/ /g;s/ +/ /g;print $a' ...

will convert nearly anything you can give it into a nice, clean, single line.

If you want to get things neater than this see the examples in Parse::RecDescent.

--
Steven Lembark                               2930 W. Palmer
Workhorse Computing                       Chicago, IL 60647
                                            +1 800 762 1582
-- 
Please see the official ORACLE-L FAQ: http://www.orafaq.com
-- 
Author: Steven Lembark
  INET: lembark_at_wrkhors.com

Fat City Network Services    -- (858) 538-5051  FAX: (858) 538-5051
San Diego, California        -- Public Internet access / Mailing Lists
--------------------------------------------------------------------
To REMOVE yourself from this mailing list, send an E-Mail message
to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in
the message BODY, include a line containing: UNSUB ORACLE-L
(or the name of mailing list you want to be removed from).  You may
also send the HELP command for other information (like subscribing).
Received on Wed May 29 2002 - 00:58:22 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US