FINDおよびGREPの代替

, PowerShell UNIX. , -. ( ), , , , bash zsh, PowerShell. , — , - - (Guderian, ApeCoder) .



UNIX find



grep



. , class



:



$ find -name \*.cpp -o -name \*.hpp -exec grep -Hb class {} \;







, PowerShell .



, grep



. PowerShell Select-String



. - :



$ Select-String class *.hpp



CustomTimeEdit.hpp:5:class CustomTimeEdit : public QTimeEdit {

DaySelecter.hpp:12: class Model : public QAbstractItemModel

DaySelecter.hpp:43: class View : public QTreeView

[...]








class



hpp



. , Select-String



: , ( -Path



), — ( -Pattern



). ( , ). , , , .



: , , (, hpp



-, cpp



-):



$ Select-String DaySelector *.hpp,*.cpp



DaySelecter.hpp:1:#ifndef __DAYSELECTER_HPP__

DaySelecter.hpp:2:#define __DAYSELECTER_HPP__

DaySelecter.hpp:10:namespace DaySelecter {

[...]








, :



$ Select-String DaySelector,MainWindow *.hpp,*.cpp



DaySelecter.hpp:1:#ifndef __DAYSELECTER_HPP__

DaySelecter.hpp:2:#define __DAYSELECTER_HPP__

DaySelecter.hpp:10:namespace DaySelecter {

MainWindow.hpp:1:#ifndef __MAINWINDOW_HPP__

MainWindow.hpp:2:#define __MAINWINDOW_HPP__

MainWindow.hpp:4:#include

[...]








, ( -Path



, -Pattern



) ( PowerShell ).



, PowerShell , ? , Select-String



:



$ Select-String DaySelector *.hpp,*.cpp | gm

TypeName: Microsoft.PowerShell.Commands.MatchInfo

Name         MemberType Definition
----         ---------- ----------
Equals       Method     bool Equals(System.Object obj)
GetHashCode  Method     int GetHashCode()
GetType      Method     type GetType()
RelativePath Method     string RelativePath(string directory)
ToString     Method     string ToString(), string ToString(string directory)
Context      Property   Microsoft.PowerShell.Commands.MatchInfoContext Context {get;set;}
Filename     Property   System.String Filename {get;}
IgnoreCase   Property   System.Boolean IgnoreCase {get;set;}
Line         Property   System.String Line {get;set;}
LineNumber   Property   System.Int32 LineNumber {get;set;}
Matches      Property   System.Text.RegularExpressions.Match[] Matches {get;set;}
Path         Property   System.String Path {get;set;}
Pattern      Property   System.String Pattern {get;set;}




, , — . (, XML). -, . , zsh.



, ; Select-String



:



, Select-String



( -Encoding



). , , , ANSI (a.k.a. WINDOWS-1251 ) OEM (CP866, «»). , ( , , ), .



, . PowerShell Get-ChildItem



, ls



( , ). UNIX' ls



, PowerShell — . , :



$ ls -r -inc *.cpp,*.hpp







— bash zsh , .. . PowerShell : PowerShell ( PowerShell, ). , .. Linux , , - . , , .



ls



. , :



$ ls -r -ex *.hpp~







- , , , , :



$ ls -r -inc *.cpp,*.hpp -ex DaySelecter*







, Where-Object



— ? PowerShell , :



$ ls -r -inc *.cpp,*.hpp -ex DaySelecter* | ? { $_.IsReadOnly }







, ls



, Select-String



. ? , Select-String



( -Path



), . , :



$ ls -r -inc *.cpp,*.hpp -ex *DaySelecter* | Select-String DaySelecter



MainWindow.cpp:26: connect(viewDaySelecter->selectionModel(),

MainWindow.cpp:38: viewDaySelecter->setDiary(diaryModel);








-, !



All Articles