bash/grep/awk/sed: How to extract every appearance of text between two specific strings

I have a text wich looks like this:

clid=2 cid=6 client_database_id=35 client_nickname=Peter client_type=0|clid=3 cid=22 client_database_id=57 client_nickname=Paul client_type=0|clid=5 cid=22 client_database_id=7 client_nickname=Mary client_type=0|clid=6 cid=22 client_database_id=6 client_nickname=Sue client_type=0|clid=10 cid=21 client_database_id=38 client_nickname=Joe client_type=0

All the text is in one line and contains no linefeeds, but the solution should also work if it did.

I need to extract the values of all clids, the result for the above should look like this

2 3 5 6 10

or

2
3
5
6
10

How can I achive this?

Hello, try:

awk 'BEGIN{FS="[ =]*";RS="|"}{print $2}' infile

Perfect! Thanks a lot.

sed 's/[ \|]/\n/g' | sed -n 's/clid=\([0-9]*\)/\1/gp'