Problems extracting word using SED

I have a file containing strings such as:

UPDATE PS_CA_BI_FF2_TA3 SET DELETE_ME = 'Y' WHERE PROCESS_INSTANCE
BI.LAST_UPDATE_DTTM FROM PS_CA_BP_LINES LINE, PS_INTFC_BI BI WHERE
EXISTS ( SELECT 'X' FROM PS_CA_BILL_PLAN BP WHERE BP.CONTRACT_NUM
[SIZE=2][FONT=r_ansi][SIZE=1]%Select(COUNTER4) SELECT COUNT(*) FROM PS_INTFC_BI WHERE INTFC_ID

I'm trying to extract all the words begining with " PS_" from the lines and only the words. The results should look like

PS_CA_BI_FF2_TA3
PS_CA_BP_LINES
PS_INTFC_BI
PS_CA_BILL_PLAN
PS_INTFC_BI

I'm using the sed command:
[/SIZE][/SIZE][/FONT]

sed -n 's/.*\([Pp][Ss]_.*\).*/\1/p' x.x

[SIZE=2][FONT=r_ansi][SIZE=1] (x.x = filename containing these strings) but I keep getting the results that look like the following:

PS_CA_BI_FF2_TA3 SET DELETE_ME = 'Y' WHERE PROCESS_INSTANCE
PS_CA_BP_LINES LINE, PS_INTFC_BI BI WHERE
PS_INTFC_BI BI WHERE
PS_CA_BILL_PLAN BP WHERE BP.CONTRACT_NUM
PS_INTFC_BI WHERE INTFC_ID

How do I stop the extract to the end of the word or space after the word? Any suggestions would be appreciated.

[/SIZE][/SIZE][/FONT]

Perhaps a dull solution, but you could convert every space to a newline and then use grep:

cat $filesname | tr " " "^J" | grep "^PS_"

Note, to generate the ^J as a single character, use the key sequence Cntrl-v Cntrl-j
The grep string is just as plain text so it is looking for start of line (the ^) then PS_

Probably not the most efficient way, but it might get you going if your just after a once only hit.

I hope that this helps,
Robin
Liverpool/Blackburn
UK

 
sed -n 's/ /\n/gp' x.x | sed -n 's/\([Pp][Ss]_.*\)/\1/p'

dc++