Re: Editing a output file
Posted in 1999
On Tue, 7 Dec 1999, Jonathan Leffler wrote:
>Well, one option is probably to avoid putting the pipe in the wrong place when doing the
>SELECT:-
>
>SELECT TKID, TKINIT, TRIM(TKFIRST) || ' ' || TRIM(TKLAST)
> FROM WHEREVER;>
>Failing that, try using either awk or 'perl in emulate awk mode', set the field separator to '|',
>then concatenate the third and fourth fields before printing the results.
>
>#--untested!
>
>awk -F'|' '{print $1, $2, $3 " " $4;}' $*
The output field separator is blank by default, so this proposed
solution doesn't work. Use:
#--tested!
awk -F'|' 'BEGIN { OFS=" ";}
{print $1, $2, $3 " " $4;}' $*
This omits the trailing pipe symbol. If you want it to appear, use:
#--tested!
awk -F'|' 'BEGIN { OFS=" ";}
{print $1, $2, $3 " " $4, "";}' $*
I'm assuming that the blanks around the pipe symbols are either handled
by the SQL or are an artefact of the posting process. However, if you
really want them, you can undoubtedly add them (it's just much more
fiddly, that's all).
>Stacey Windsor wrote:
>> I have a SQL command that runs each night against my database to generate an output
>> file, but the output is not quite right. The output format is as follows:
>>
>> TKID | TKINIT | TKFIRST | TKLAST
>>
>> 1 | RAB | Robert A. | Banks |
>> 2 | DEC | David R.| Cunningham |
>> 3 | MRD | Mathew R. | Donaldson |
>>
>> Is the a way to write a script, use VI or a third party program to
>> edit this file to remove the pipe symbol (and extra space) from
>> between the TKFIRST and TKLAST so that the final format looks like
>> this:
>>
>> 1 | RAB | Robert A. Banks |
>> 2 | DEC | David R. Cunningham |
>> 3 | MRD | Mathew R. Donaldson |
--
Yours,
Jonathan Leffler (jonathan.leffler@informix.com) #include <disclaimer.h>
Guardian of DBD::Informix v0.62 -- http://www.perl.com/CPAN
"I don't suffer from insanity; I enjoy every minute of it!"