grep文件的通用方法,包括第n个父目录

时间:2017-05-21 17:10:08

标签: bash ubuntu scripting grep

我很想知道;有没有办法从第n个前任目录grep? 例如,假设我有一个脚本,其中包含grep命令,位于给定路径下:

/home/usr/project/utilities/wheremyscriptsits/myscript.sh

我想从这条道路开始我的grep程序:

/home/usr/project

如果没有明确指出路径,有没有办法做到这一点? 例如maxdepth类似于父级别的功能。

感谢您的时间和兴趣。

1 个答案:

答案 0 :(得分:0)

你的问题不是很清楚,但如果我理解你,那么像这样的东西对于大多数情况都适用于bash:

#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Delaunay_triangulation_2.h>
#include <CGAL/Triangulation_vertex_base_with_info_2.h>
#include <CGAL/Point_set_2.h>
#include <vector>

typedef CGAL::Exact_predicates_inexact_constructions_kernel       K;
typedef CGAL::Triangulation_vertex_base_with_info_2<unsigned, K>  Vb;
typedef CGAL::Triangulation_data_structure_2<Vb>                  Tds;
typedef CGAL::Delaunay_triangulation_2<K, Tds>                    Delaunay;
//typedef Delaunay::Point                                             Point;
typedef CGAL::Point_set_2<K,Tds>::Edge_iterator                   Edge_iterator;
typedef CGAL::Point_set_2<K,Tds>::Vertex_handle                   Vertex_handle;
typedef K::Point_2                                                Point_2;

CGAL::Point_set_2<K,Tds> PSet;

int main()
{
  std::vector< std::pair<Point_2,unsigned> > points;
  points.push_back( std::make_pair(Point_2(0,0),0)   );
  points.push_back( std::make_pair(Point_2(1,0),1)   );
  points.push_back( std::make_pair(Point_2(0,1),2)   );
  points.push_back( std::make_pair(Point_2(14,4),3)  );
  points.push_back( std::make_pair(Point_2(2,2),4)   );
  points.push_back( std::make_pair(Point_2(-4,0),5)  );

  PSet.insert(points.begin(),points.end());
   // init
  Point_2 actual(30,45,10);
  // nearest neighbor ...
  Vertex_handle v = PSet.nearest_neighbor(actual);
  std::cout << "Nearest neighbor:" << v->point() << "\n";
  // k nearest neighbors ...
  std::vector<Vertex_handle> L;
  std::vector<Vertex_handle>::const_iterator it;
  PSet.nearest_neighbors(actual,5, std::back_inserter(L));
  std::cout << "actual point: " << actual << "\n";
  for (it=L.begin();it != L.end(); it++)
      std::cout << it->info() << "\n";
  return 0;
}

有关详细信息,请参阅http://mywiki.wooledge.org/BashFAQ/028