How to strip strins

Guys,

Please can someone tell me how to strip each string from the following ?

TABLE1||METHOD||TYPE||STATUS||DATE

What i need is to assign each value to the variable

TABLE1 to var1
METHOD to var2
and so on

If there is NULL in one of them, something like A||B||||C||
I want the third to be displayed as a space

I am using ksh by the way

Thanks
Ganesh

go for awk

do man awk for more info

Don't quite understand AWK.. I think there is lot to learn in awk ? Is it possible to give an example ?

the thing is it seems loke a homework problem, otherwise would have deinitely helped you

ok atleast post what have u tried so far

Ok thanks.. Definitely not home work.. I am working and this is what i wrote

runsql_analyze_db() {
echo "I am in runsql_analyze_db and the parameter is $1"
statement=$1
echo " The process id in SQL is $$"
echoLog "$statement started at `date`"
sqlResult=`$BINDIR/sqlplus -s <<SQL
######/#######
WHENEVER SQLERROR exit 10
set feedback off
set heading off
set pagesize 100
exec dbms_stats.gather_table_stats($statement
exit
SQL
`
echo "SQL RESULT is $sqlResult"
echoLog "Completed at `date`"
checkORA "$sqlResult" $2
}

submit()
{
chk_process=1
stmt1="update analyze_table set status = NULL;"
echo " The process id in submit is $$"
echo "Now i am in submit"
for collect_stat in `$BINDIR/sqlplus -s <<EOF
xchtbl/xchtblint3
set heading off
set feedback off
set linesize 132
set pagesize 100
select 'ownname=>''' || owner
||''',tabname=>''' || table_name
||''',granularity=>''' || granularity
||''',cascade=>' || cascade
||',method_opt=>''' || NVL(method_opt,'''')
||');'
from analyze_table;
exit
EOF
`
do

I am planning to take the table name from above and fetch rest of the records in the SQL plus to analyze a table. I am running out of ideas.

Thanks

ok

similarly $2 for var2
$3 for var3 and so on
this should work.
if still some problem post back

Gaurav

Thanks Gaurav.

Did not quite work as anticipated

xchbot1:/ford/app/oracle/product/920/dbs $ echo GANESH||TEST||MIST | awk -F '||' '{print $1}'
GANESH
xchbot1:/ford/app/oracle/product/920/dbs $ echo GANESH||TEST||MIST | awk -F '||' '{print $2}'
GANESH
xchbot1:/ford/app/oracle/product/920/dbs $ echo GANESH||TEST||MIST | awk -F '||' '{print $3}'
GANESH

hi Ganesh,
there is a problem i m trying to sort it out.
by the time use this dirty solution

echo "GANESH||TEST||MIST" | awk -F '|' '{print $1}'

$3 will give TEST
$5 will give MIST

note the "" given around the string

Gaurav

one more thing use the -F '|'
and $3 for var2
$5 for var3

giving -F '||' is not working, its giving error even i am not able to work it out.

maybe some guru can throw some light on it

Gaurav

-F take only character in standred awk. Some advance version can take regexp as argument to -F
You can use an another (may be ugly) approach
echo "GANESH||TEST||MIST" | awk --posix ' {
split($0, a, /\|\|/) ;print a[1]" "a[2]" "a[3]" "a[4]}'

finally got it

will give GANESH

$2 for TEST
$3 for MIST
and so on

Gaurav

Did not quite work as anticipated

xchbot1:/ford/app/oracle/product/920/dbs $ echo GANESH||TEST||MIST | awk -F '||' '{print $1}'
GANESH
xchbot1:/ford/app/oracle/product/920/dbs $ echo GANESH||TEST||MIST | awk -F '||' '{print $2}'
GANESH
xchbot1:/ford/app/oracle/product/920/dbs $ echo GANESH||TEST||MIST | awk -F '||' '{print $3}'
GANESH

echo "GANESH||TEST||MIST" | nawk -F '\\|\\|' '{print $1}'

OR

echo "GANESH||TEST||MIST" | nawk -F '[|][|]'  '{print $1}'

Hey Ganesh,

May be you have not looked and tried my last post before posting this.
Atleast care to look for posts carefully before posting a new post.
One more thing enclose your string in "". like echo "string" | awk......

Gaurav