get the table names from file using UNIX Script
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
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.
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
精彩评论