Cherry picking with sed?

#!/bin/bash

shuffle() 
{
Deck=$(shuf -e {2,3,4,5,6,7,8,9,T,J,Q,K,A}{H,S,D,C})
}

PH=(6H 9S KC)  # playerhand
CH=(JD 4D)        # computerhand
AC=2S                # activecard

shuffle
echo $Deck

I am unsure about how to proceed. I want to reshuffle a deck but without the cards in $PH, $CH, and $AC. Could it be done using sed? Any help would be greatly appreciated.
Thank you in advance.
Cogiz

How did you get to a point where you have dealt at least six cards from a deck, but don't know what cards remain in that deck? One might guess that in most card games you would have known hands for various players, a know set of cards in a discard pile, and a known set of cards remaining in the deck. In a state like this, it would seem to be fairly easy to "shuffle" the discard pile and the current contents of the deck to produce an updated deck rather than create a new deck of 52 cards (some of which duplicate other cards in play).

But, having said that, how do you plan to remove a card from the "deck" when a card is drawn from the deck? Is there any reason why removing the top card from the "deck" should be much different from removing any other card from the "deck"?

Don is absolutely right. This is not a question of how to use a certain tool (you mentioned sed but the same goes for any other likewise). You should look at your data structure and how you handle that instead.

My suggestion is to use a (fixed) array of cards. This array of 52 (or, depending on what deck of cards you want to use a different number) elements (cards) then is filled with a location of the card, i.e "" for the card being the deck, "P" for it being in the player hand, "D" for it being in the discard pile, etc..

The process of dealing a card to the player then means to change the contents of the respective element in the cards-array from "" to "P" - analogously with all the other movements of cards. This way you just query the array for all the cards with value "P" (=the content of the player hand) and so on.

I hope this helps.

bakunin

Fully seconding my esteemed colleagues' advice that it definitely pays off to do a decent planning on data structures, algorithms, and desired outcomes instead of doing a later repair of accidents or errors, here's two hints on how to remove several cards from a fully shuffled full deck (assuming a recent bash shell):

for CU in ${PH[@]} ${CH[@]} $AC; do Deck=${Deck/${CU}$'\n'/};done
OI="$IFS"; IFS=$'\n'; grep -vf <(echo "${PH
[*]}$IFS${CH
[*]}$IFS$AC") <(echo "$Deck"); IFS="$OI"