Read control file using unix?

February 10, 2011 at 03:35:25
Specs: Windows 7
Hi

I want to read a control file and direct the output to a new file using shell script.

Sample input:

OPTIONS ( ERRORS=10000)
load data
CHARACTERSET UTF8
INFILE '/users/abc.txt'
BADFILE '/users/abc.bad'
DISCARDFILE '/users/abc.dsc'
DISCARDMAX 10
Truncate
INTO TABLE TEST_TABLE
FIELDS TERMINATED BY '|'
TRAILING NULLCOLS
(
Column1 ,
Column2 ,
Column3 ,
Column4 ,
Column5 ,
Column6
)

Desired output:

Select TABLE2. Column1||'|'||
TABLE2. Column2||'|'||
TABLE2. Column3||'|'||
TABLE2. Column4||'|'||
TABLE2. Column5||'|'||
TABLE2. Column6||'|'||
from shema.TABLE2


See More: Read control file using unix?

Report •

#1
February 10, 2011 at 12:49:27
This looks like homework. I'll do the hard part and leave it to finish the last line.

HINT: use awk's END pattern to execute text after the last line - similar to BEGIN below:

#!/bin/ksh

# if using Solaris Unix, use nawk
awk ' BEGIN { tabname="TABLE2"
printf("%s", "Select ")
}
{
if($0 ~ /FIELDS TERMINATED/)
   termer=$NF # last field is terminator

# if line starts with Col
if($0 ~ /^Col/)
   {
   gsub(",", "", $0) # get rid of the ,
   printf("%s. %s,||%s||\n", tabname, $0, termer)
   }

} ' sampleinput.txt


Report •
Related Solutions


Ask Question