Re: Unload command help
Posted in 1998
Topics: Storage & Space Management, Server Administration, Migration, Import/Export & Data Conversion
How about creating a file called, say, "do" which contains the following:-
isql nsoe - << EOF
select field1 from table; EOF
and then saying the following at the unix prompt:-
do | sed 's/$/ /' | cut -c1-20 > outputfile
That is, never mind unload; just take the output of "select field1 from table"
and pipe it through "sed" to add twenty blanks to the end of each line, then
pipe that through "cut" to get the first twenty characters in each row. Seems
like it should work.
You'll need to edit the first few lines out of "outputfile" because "do"
will output
+-------------
|
|field1
|
|000AAABB
|000AAAC
|000AAAD
|...
rather than
+-------------
|000AAABB
|000AAAC
|000AAAD
|...
- Paul (not a spokesman)
article <35802FEF.C1ABA565@mci.com>, David Hinz <David.Hinz@mci.com> wrote:
>I need help with an unload command to do the following:
>
>- The table has one field: field1 char(10)
>- All the records in the table look like "0000000ABC" or "0000000AB"
>- I need to unload the data into a ASCII file that has no delimiter and
> every record is padded with spaces to 20 characters.
>
>Just doing:
>dbaccess user@database - << EOF
>unload to '/tmp/unload.data'
>select field1 from table;>EOF
>
>Will create a file that uses the default delimiter ("|") and each record
>looks like:
>0000000ABC|
>0000000AB|
>
>Questions:
>What can I use for the delimiter parameter so that I don't get one? I
>tried using "delimiter '' " but that puts a \\0 in for the delimiter.
>
>How can I pad each line of data to 20 bytes, with spaces, within the one
>line. I could dump the file as described above then use a script to
>replace the "|" with the spaces but I would rather do it in one file
>(there is almost a million rows of data and I don't have disk space for
>a temporary copy).
>
>
>Also, by default does the LOAD command truncate all trailing blanks?
>
>Thanks,
>dave.