複数のパスを含むテキストファイル(.txt)があり、それをフィルタリングしてパスのリストだけを残したいと思います。
ファイルは次のとおりです。
Loremipsumdolorsitametconsecteturadip"/one/path/I_want_to_keep"iscingelitseddoeiusmodtemporincididuntutlaboreetdoloremagnaaliqua
Utenimadminimveniamquisnostrudexercitationul"/another/path/I_want_to_keep"lamcolaborisnisiutaliquipexeacommodoconsequat
Duisauteiruredolorinreprehenderitinvoluptatevelitess"/another/path/I_want_to_keep"ecillumdoloreeufugiatnullapariatur
Excepteursintoccaecatcupidatatnonproident"/another/path/I_want_to_keep"suntinculpaquiofficiadeseruntmollitanimidestlaborum
例に示されているパスには引用符( "")で囲まれた3つのスラッシュ(/)があり、パスの最後の部分はアンダースコア(_)で区切られた複数の単語であり、周囲のテキストには特定のパターンはありません。
私はzsh 5.8(x86_64-apple-darwin21.0)を使用しています。
ベストアンサー1
私はこれを提供する:
% grep -o '"/[^"]*"' file
"/one/path/I_want_to_keep"
"/another/path/I_want_to_keep"
"/another/path/I_want_to_keep"
"/another/path/I_want_to_keep"