だから私に必要なのは、私の一致パターン間(および含む)間のテキストだけをgrepすることです。
次のようなものです(テキストは気にしないでください。ただ横説説です:D):
asdgfasd gasd gdas g This will be this one day ksjadnbalsdkbgas asd gasdg
asdgasdgasdg dasg dasg dasg This will be this next day adf gdsf gdsf sdfh dsfhdfsh
asdf asdf asd fesf dsfasd f This will won' not this day asdgadsgaseg as dvf as d vfa se v asd
dasfasdfdas fase fasdfasefase fasdf This not what shoes day asdjbna;sdgbva;sdkbcvd;lasb ;lkbasi hasdli glais g
だから私が欲しいのはこれです:
cat theabovetext|grep -E "^This * day$"
出力:
This will be this one day
This will be this next day
This will won' not this day
This not what shoes day
したがって、基本的に私は「This」と「Day」の間(「This」と「day」を含む)の間に文字数や「This」の前と「Day」の後に何文字があるかに関係なくテキストを取得したいと思います。性格。入力がすべて1行にある場合でも機能する必要があるため、次のようになります。
asdgfasd gasd gdas g This will be this one day ksjadnbalsdkbgas asd gasdg asdgasdgasdg dasg dasg dasg This will be this next day adf gdsf gdsf sdfh dsfhdfsh asdf asdf asd fesf dsfasd f This will won' not this day asdgadsgaseg as dvf as d vfa se v asd dasfasdfdas fase fasdfasefase fasdf This not what shoes day asdjbna;sdgbva;sdkbcvd;lasb ;lkbasi hasdli glais g
次のように出力する必要があります。
This will be this one day This will be this next day This will won' not this day This not what shoes day
ここでの出力はまだ一行にあります。
ベストアンサー1
GNUを使用すると、grep
次のことができます。
grep -o 'This.*day' theabovetext
(ファイルの読み方を知っているので、cat
必要はありません。)grep
この-o
フラグは、パターンに一致する行部分のみが表示されることを示します。
他のバージョンでもこのフラグをサポートしているようですが、grep
POSIXにはないので必ずしも移植可能ではありません。