ROS filter topic list from rosbag via shell script

2 篇文章 0 订阅

This script was modified from a weblog,

https://blog.csdn.net/moyu123456789/article/details/86738718

#!/bin/bash

# filter topic list, just key word
filter_topic_key_words=("car" "localization")

#1.get the info of the bag
if [ $# != 2 ]; then
   echo "the input params number is not 2,please try again!"
   exit 1
fi
rosbag info $1 > bag.txt
#2.get the delete topics form the bag
bag_file=./bag.txt

for key_word in ${filter_topic_key_words[@]}
do
    for line in $(grep "/$key_word/" $bag_file)
    do
        result=$(echo $line | grep "/$key_word/")
        if [[ "$result" != "" ]]
        then
                echo $line >> topics.txt
        fi
        #echo $line >> topics.txt
     done
done

topic_file=./topics.txt
if [ ! -s $topic_file ]
then
       echo "there is no specify topic in the $1 bag."
       read
       exit 1
fi

#3.create the commands to delete the topics
line_count=0
topicinfo=""
for line in $(cat $topic_file)
do
    if [ 0 == $line_count ];then
        topicinfo="topic!='$line'"
    else
        topicinfo=$topicinfo" and topic!='$line'"
    fi
    line_count=$line_count+1
done

echo "rosbag filter $1 $2 ""\""$topicinfo"\"" > rosbag.sh
#4.execute the cmd
chmod 777 rosbag.sh
./rosbag.sh
echo "###########the new bag $2 has created now#############"
#5.delete the files no need

rm -rf bag.txt
rm -rf topics.txt
rm -rf rosbag.sh


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值