bash、awk、sed、またはperlを使用して線形コマンドの次の行でsdXのみをキャプチャする方法は?
echo ""dfs.datanode.data.dir" : "/rid/sdb/oo/hdfs/data,/rid/sdc/oo/hdfs/data,/rid/sdd/oo/hdfs/data,/rid/sde/oo/hdfs/data,/rid/sdf/oo/hdfs/data","
期待される出力
sdb
sdc
sdd
sde
sdf
ベストアンサー1
あなたはそれを使用することができますグレブ議論:
-P, --perl-regexp
Interpret the pattern as a Perl-compatible regular expression
(PCRE). This is experimental and grep -P may warn of
unimplemented features.
-o, --only-matching
Print only the matched (non-empty) parts of a matching line,
with each such part on a separate output line.
したがって、あなたのコマンドは次のようになります
echo ""dfs.datanode.data.dir" : "/rid/sdb/oo/hdfs/data,/rid/sdc/oo/hdfs/data,/rid/sdd/oo/hdfs/data,/rid/sde/oo/hdfs/data,/rid/sdf/oo/hdfs/data"," | grep -oP "\w*sd\w*"
sdb
sdc
sdd
sde
sdf