首页 > 解决方案 > sed 特定的精确数学

问题描述

我有一个 file.txt,其中包含例如

/tmp/blabla/
/tmp
/blabla/tmp/muzi
/muzi/puzi/bla/bla/tmp

我需要编写一个接受用户输入的函数,然后继续删除文件中的 EXACT 匹配项


function Remove_Project_Dir () {
  [[ $(grep -w $1 $version_db_file | wc -l) != 0 ]] && sed -i '/"$1"/d' $version_db_file || echo "Directory supplied doesnt exist in version db"


}

#Should only remove /tmp if there's such thing
Remove_Project_Dir /tmp

我在使用包含“/”的 sedding 字符串时遇到问题,也找不到如何只删除完全匹配的内容。任何帮助将不胜感激

标签: bash

解决方案


推荐阅读