Extracting part of a string

Hi all,
I have to extract only the second part of a database column (VARCHAR) and the value is seperated by a "~"

xyz~
chxyz36r~
abder~000082685
mnops~000083554
fulfil302~00026

Above are some examples of the values and for each record I have to extract the value after "~" , if there is a value by using shell scripts. As you can see they are multiple lenghts and in multiple formats and the only way to seperate them is by a "~".
Thanks in advance.

How about this...

$ cat script
#! /usr/bin/ksh

echo "xyz~
chxyz36r~
~whatif
abder~000082685
mnops~000083554
fulfil302~00026" | while read line ; do
        one=${line%%~*}
        two=${line##*~}
        printf "%30s %15s %15s \n" "$line" "$one" "$two"
done
exit 0
$ ./script
                          xyz~             xyz
                     chxyz36r~        chxyz36r
                       ~whatif                          whatif
               abder~000082685           abder       000082685
               mnops~000083554           mnops       000083554
               fulfil302~00026       fulfil302           00026
$

awk -F "~" '{print $2}'

If you don;t want empty lines ,

awk -F "~" '{print $2}' | grep -v ^$

awk -F "~" '$2 !~ /^$/ {print $2 }' "file"

cat $filaname | sed 's/.*~\(.*\)/\1/'

cut -d"~" -f2 filename

Hi all,
Thanks for all the answers..based on the above answers I modified the below script ..

Here is the input file...
XYZ-2066779% xyz~%
XYZ-000036480% chxyz36r~%
XYZ-2056453% abder~000082685%
XYZ-3038583% fulfil302~00026%

I need to extract the first part before '%' and the second part after '~' and before '%'

so my output must be
XYZ-2066779
XYZ-000036480
XYZ-2056453 000082685
XYZ-3038583 00026

The script is:

while read LINE
do
NEWC_ID=`echo $LINE | awk -F'%' '{print toupper($1)}'`
NEWF_ID=`echo $LINE | awk -F'%' '{print ($2)}'`
NF_ID=`echo $NEWF_ID | sed s/\'/\'\'/g`
C_ID=`echo $NEWC_ID | sed s/\'/\'\'/g`
F_ID=`echo $NF_ID | awk -F'~' '{print ($2)}'`

echo $C_ID
echo "-----"
echo $F_ID
echo "-----"

done < $loc/input.txt

Please let me know if there is a better way of implementing the above script..

Thanks in advance..

sed -e 's/\(.*\)%.*~\(.*\)%/\1\2/' input_file

awk 'BEGIN { FS = "%" }
  { 
    n = split($2,array,"~")
    print $1 " " array[2]
  }
' "file"

output:

 # ./test.sh
XYZ-2066779
XYZ-000036480
XYZ-2056453 000082685
XYZ-3038583 00026