0

I am having a sample file as given below. This is an SQL Loader control file:

LOAD DATA
APPEND
INTO TABLE XXWIN_TMP_LOADER_TAB
(  seq         POSITION(1:10)  INTEGER EXTERNAL
  ,h_record    POSITION(11:20) CHAR
  ,h_file_name POSITION(21:55) CHAR
)
APPEND
INTO TABLE XXWIN_SQL_LOADER_TAB
(  seq         POSITION(1:10)  INTEGER EXTERNAL
  ,h_record    POSITION(11:20) CHAR
  ,h_file_name POSITION(21:55) CHAR
)
APPEND
INTO TABLE XXWIN_SQL_LOADER_TAB
(  seq         POSITION(1:10)  INTEGER EXTERNAL
  ,h_record    POSITION(11:20) CHAR
  ,h_file_name POSITION(21:55) CHAR
)

I would like to select any number of table names occurring in the file which are starting with 'XX_' and ending with '_TAB' and store it into an array using an UNIX script.

Please advice.

Thanks, Arun

2 Answers 2

2

If the file syntax is not changing (the table names start with XX, not XX_):

tnames=`grep -o "TABLE XX[^ ].*_TAB" <file_name> | sed 's/TABLE //g'`
for tn in $tnames; do echo $tn; done

Change the <file_name> to the name of the file.

Sign up to request clarification or add additional context in comments.

2 Comments

Not Working, I wrote it like this:#!/usr/bin/ksh clear echo "Test Scripts Running" echo tnames=grep -o "TABLE XX[^ ].*_TAB" DATA_LOADER_CTL.ctl | sed 's/TABLE //g' for tn in $tnames; do echo $tn; done This is giving my no output.
echo tnames=... doesn't assign tnames. Remove echo. Also, I wrote it for sh (which sh).
0

You don't say which shell, but since sh doesn't support arrays I'm assuming Bash.

tables=($(sed -n '/TABLE /s/TABLE \(XX[^ ]*TAB\) *$/\1/p' inputfile))
for table in ${tables[@]}
do
    echo "$table"
done

1 Comment

Did work out.... #!/usr/bin/ksh clear echo "Test Scripts Running" echo tables=($(sed -n '/TABLE /s/TABLE (XX[^ ]*TAB) *$/\1/p' DATA_LOADER_CTL.ctl)) for table in ${tables[@]} do echo "$table" done echo "Done"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.