Sed to search for 2 patterns, if the first pattern does not exist, print the second pattern

I have a question about sed. From this input:

[/=TueGreen$58.30Orange5:36pmSat*=WedOrange$76.63Purple6:20pmTue] [/=Thu6:06pm$09.05Blue11:32amMon/=Thu1:38am$56.41Red4:25amThu] [/=Sun1:49pm$12.41Yellow2:51pmMon*=FriOrange$49.68Blue1:24pmTue] [/=Sat11:58am$82.24Orange3:44amMon*=Thu1:08am$33.49Red8:21amSat] 

I need to conclude:

 $58.30 6:06pm$09.05 1:49pm$12.41 11:58am$82.24 

I know the pattern seems so easy, but I could not even find the time pattern. Because the hour is sometimes 1 or 2 digits.

This is the third day I studied sed and searched for an answer. I recognized grep. So simple if you use grep. But this assignment makes me use sed. So far this is my sed command:

 sed 's/.*\([0-9]*:[0-9]*\(am\|pm\)\).*/\1/' FILE 

The results show only minutes and am / pm. Each input line has many temporary patterns. But my result shows the last time pattern in each row. As you can see below:

 :20pm :25am :24pm :21am 

Where am I wrong?

+6
source share
1 answer

Here you go:

 sed -e 's/[^$0-9]*\([0-9:]*[ap]m\)*\(\$[0-9.]*\).*/\1\2/' 
+5
source

All Articles