xztaityozx / shellinq

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ShelLINQ

ShelLINQ is LINQ for Shell.

logo

(I am using google translation to write this.)

Description

ShelLINQ is a shell command that allows you to use LINQ provided by .NET framework with Bash and others. it can filter data passed from standard input and pipe data using queries such as LINQ.

Usage

shellinq [TYPEs] [method query] ... [-o [FORMAT]]

[TYPEs] is the type of input data.
For int type, specify [int]. If not specified, ShelLINQ expects from int, double, or string.
If there are multiple columns like the ls -l command, specify them in the order of [type1, type2, ..., typeN]. If you do not specify it, ShelLINQ forecasts it all.

[method query] is the query part.
For [methond], specify the method name provided by LINQ like Select or Where. [query] is an argument part to be given to the method.
For example,

Where (x => x% 2 == 0)

writes

where 'x => x% 2 == 0'.

In [query], you can use $ for column specification like awk.
For example if you write where '$ 1% 2 == 0' ShelLINQ interprets where '_ => _% 2 == 0'.
With $0 all columns can be specified.

[-o [FORMAT]] is used to specify the output format with C # code. Specifically, it specifies the block part of the foreach loop using the processed data. Since the retrieved item is stored in the variable item it is a good idea to use it. For example,
Input

% seq 30|shellinq select '$1%2==0' -o 'Console.WriteLine(item?"even":"odd");'

output

odd
even
odd
even
.
.
.

Demo

demo1

demo2

demo3

Install

git clone https://github.com/xztaityozx/shellinq
./shellinq/install.sh

Requierment

mcs
mono

説明

使い方

shellinq [TYPEs] [method query] ... [-o [FORMAT]]

[TYPEs]は入力データの型です。int型の場合は[int]と指定します。指定しない場合はint,double,stringのどれかからShelLINQが予想します。
ls -lコマンドのように複数のカラムがある場合は[type1,type2,...,typeN]というように順番に指定します。これも指定しない場合はShelLINQがすべて予想します。

[method query]はクエリ部分です。methodにはSelectWhereのようにLINQが提供するメソッド名を指定します。Qにはメソッドに与える引数部分を指定します。
例えば

Where (x => x% 2 == 0)

where 'x => x% 2 == 0'.

と書きます。
queryではawkのようにカラムの指定に$が使えます。
例えばwhere '$1%2==0'と書けばShelLINQはwhere '_=>_%2==0'と解釈します。
$0を使うとすべてのカラムが指定できます。

[-o [FORMAT]]は出力フォーマットをC#のコードで指定するときに使います。 具体的には処理されたデータを使ったforeachループのブロック部を指定します。
取り出されたアイテムは変数itemに格納されているのでそれを使用するといいでしょう。

Input

% seq 30|shellinq select '$1%2==0' -o 'Console.WriteLine(item?"even":"odd");'

output

odd
even
odd
even
.
.
.

インストール

git clone https://github.com/xztaityozx/shellinq
./shellinq/install.sh

必要なもの

monomcsが必要です

About


Languages

Language:Shell 100.0%