split string

Hi
I am facing a problem in spitting a string.

Here is the string
--------------------
subject1=10;subject2=30;subject3=40;subjectcode=10001;...

Now, I want only marks not the subject code. (there can be 'n' subjects)
ie.
10
30
40

My doubt
----------
How do I look for subject'n'= (where 'n' is number). I want to ignore if there is any characters between subject and =.

Try:

echo 'subject1=10;subject2=30;subject3=40;subjectcode=10001;../..' |
tr ';' '\n' | sed -n 's/subject[0-9]\+=\([0-9]\+\)/\1/p'
10
30
40
 
$ nawk -F"[=;]" '{for(i=2;i<=NF;i=i+2)print $i}' test                                                                                              
10
30
40
10001

 
$ cat test 
subject1=10;subject2=30;subject3=40;subjectcode=10001;

---------- Post updated at 11:01 AM ---------- Previous update was at 10:55 AM ----------

i didnt read your question properly... try the below ( test is the input file name )

 
$ nawk -F"[=;]" '{for(i=1;i<=NF;i++){ if($i~/subject[0-9]/) {print $(i+1)}}}' test                                                                 
10
30
40

IFS=';'
set -f
set -- $string
set +f

for n
do
  case $n in
    subject*[!0-9]*=*) continue ;;
    subject*) printf "%s\n" "${n#*=}" ;;
  esac
done

Another option

awk -F"=|;" '{ for(i=2;i<=NF;i=i+2){print $i} }' infile

regards,
Ahamed

---------- Post updated at 10:25 PM ---------- Previous update was at 10:23 PM ----------

Ooops... please ignore the above code... I missed out the actual requirement...
My code also will boil down to itkamaraj's code... :slight_smile:

regards,
Ahamed

Thanks a lot...
It Worked :slight_smile: :slight_smile: :slight_smile: