I need to "swap in" new "BT MAC address" values so that Alsa will direct the bluetooth stream to whichever device I want.
There is probably an awk, grep or sed one liner that will do what I need, but at this stage i am trying to go step by step and learn as I go.
When the file is in it's original state the BT_MAC_address is in it's generic form ie: XX:XX:XX:XX:XX:XX and the user needs to manually change it to match the desired output device.
(see /root/.asoundrc file contents at bottom of post)
I can use sed to replace the generic MAC as follows:
Code: Select all
sed 's/\(.*\)"XX:XX:XX:XX:XX:XX"/\1"F2:FA:91:DD:FA:C6"/' asoundrc.txt > asoundrcTMP.txt
I tried using awk to identify the field that occurs after the "second occurrence of string: 'device' " as follows:
Code: Select all
OLDBTMAC= awk '$1=="device" {print $2}' /root/asoundrc.txt
echo $OLDBTMAC
Code: Select all
sed 's/\(.*\)`$OLDBTMAC`/\1"F2:FA:91:DD:FA:C6"/' asoundrc.txt > asoundrcTMP.txt
I tried various ways to "escape" the $OLDBTMAC but could not hit the sweet spot.
Any ideas what I have to do to bring a variable into sed?
Here are the original contents of the default /root/.asoundrc file:
Code: Select all
### these three lines enable the regular sound card ###
defaults.pcm.card 0
defaults.pcm.device 0
defaults.ctl.card 0
##################
ctl.equal {
type equal;
}
pcm.plugequal {
type equal;
slave.pcm "plughw:0,0";
}
pcm.equal{
type plug;
slave.pcm plugequal;
}
### these two lines enable the equalizer ###
#pcm.!default pcm.equal
#ctl.!default ctl.equal
################
pcm.bluetooth {
type plug
slave.pcm {
type bluealsa
interface "hci0"
device "XX:XX:XX:XX:XX:XX"
profile "a2dp"
}
}
ctl.bluetooth {
type bluealsa
}
### these two lines enable bluetooth ###
pcm.!default pcm.bluetooth
ctl.!default ctl.bluetooth