Download the script, then
chmod +x ros2_bag_play_exclude.sh
./ros2_bag_play_exclude.sh <ros2_bag_file> /topic_to_exclude /more_topics_to_exclude /wild_card_match*
| bag_path=$1 | |
| topics=`ros2 bag info ${bag_path} | grep "Topic information" | awk '{print $4}'` | |
| topics+=" " | |
| topics+=`ros2 bag info ${bag_path} | grep Topic | grep -v "Topic information" | awk '{print $2}'` | |
| no_faults=true | |
| for exclude in "${@:2}"; do | |
| if [[ "${topics}" != *${exclude}* ]]; then | |
| echo "Can't find topic name ${exclude}" | |
| no_faults=false | |
| continue | |
| fi | |
| found=false | |
| for topic in ${topics//" "/ } ; do | |
| if [[ ${topic} == ${exclude} ]]; then | |
| topics=${topics//${topic}/} | |
| found=true | |
| fi | |
| done | |
| if ! ${found}; then | |
| echo "Topic name ${exclude} may be incomplete" | |
| no_faults=false | |
| fi | |
| done | |
| if ${no_faults}; then | |
| ros2 bag play ${bag_path} --topics ${topics} | |
| fi |