Re: need to trim spaces from sqlplus output

From: Andrew Kerber <andrew.kerber_at_gmail.com>
Date: Mon, 24 Jan 2011 07:12:52 -0600
Message-ID: <AANLkTikO7ckgbwnwtYEYQTTwcD5+S+NPsOKWPqNR+SQC_at_mail.gmail.com>



Thanks everyone for the info. I will be implementing this week, and I will let you know how it went.

On Sun, Jan 23, 2011 at 11:26 PM, De DBA <dedba_at_tpg.com.au> wrote:

> I don't know if this is already answered or not, excuse me if it is.
>
> As a Perl nut, I do believe that there's something to say for using sed to
> do stream editing, nothing laughable about that ;) . To complete the sed
> command:
>
> sed -e 's/[\ \t]*|/|/g' \
> -e 's/|[\ \t]*/|/g' \
> -e 's/^[\ \t]*//' \
> -e 's/[\ \t]*$//'
>
> Note there is an escaped space (\ ) before the escaped t (tab - \t ). This
> will strip whitespace (excluding newlines) from the beginning and end of
> each column, including leading and trailing columns. If you use a sql script
> you can easily incorporate it as:
>
> sqlplus -s / _at_my.script | sed -e 's/[\ \t]*|/|/g' -e 's/|[\ \t]*/|/g' -e
> 's/^[\ \t]*//' -e 's/[\ \t]*$//'
>
> Cheers,
> Tony
>
>
> Andrew Kerber wrote:
>
>> Well, the trouble is I do actually need a delimiter there, I am using set
>> colsep '|' so I have a pipe delimiter. If there was a way to trim the data
>> before the column separator it would be nice, but I couldnt figure out any
>> way to do it. I ended up using a sed command to trim the resulting output
>> that seems to work.
>>
>> sed 's# *|#|#g' infile.csv | sed 's/|[ ]*/|/g' > output.txt
>>
>> Probably a real sed guru wouldnt need the pipe, and no doubt a perl guy
>> would laugh at this, but it gets the job done for a guy whose primary
>> Unix/Linux experience comes from having to figure stuff out from the dba
>> point of view.
>>
>>
>>
>> On Wed, Jan 19, 2011 at 10:13 AM, <Joel.Patterson_at_crowley.com <mailto:
>> Joel.Patterson_at_crowley.com>> wrote:
>>
>> <snip>
>>
>
>
>
>
> --
> http://www.freelists.org/webpage/oracle-l
>
>
>

-- 
Andrew W. Kerber

'If at first you dont succeed, dont take up skydiving.'

--
http://www.freelists.org/webpage/oracle-l
Received on Mon Jan 24 2011 - 07:12:52 CST

Original text of this message