回答:
他のいくつかの方法:
sed
sed 's/.*(\(.*\))/\1/' file perl
perl -pe 's/.*\((.*)\)/$1/' file
または
perl -lanF"[()]" -e 'print $F[1]' file
または
perl -pe 's/.*\((.+?)\).*/$1/;' file awk
awk -F"[()]" '{print $2}' file シェル
while IFS="()" read a b; do echo "$b"; done < file -F使用すると、awkが行をフィールドに分割するために使用する文字を選択できます。ここでは、[]開き括弧と閉じ括弧で構成される文字クラス()を指定しています。そのため、行を何度も分割(し)ます。その結果、2番目のフィールドは括弧の内容になります。例えば、文字列でG8 = P(G1,G3)foo、$1なりますG8 = P、$2となりますG1,G3と$3なりますfoo。
grep -oP '\(\K[^)]+' file
これは開き括弧を探し、無視し、その後に続く閉じ括弧以外のすべての文字を出力します。
GNU grepが必要
sed 's/^.*(//;s/)$//' /path/to/file
これを分解するには:
sedあるstreamのeditorは。 's/^.*(//;s/)$//'に送信されるスクリプトsedは次のとおりです。
s/^.*(// substitute nothing for the beginning of any line (`^`) followed by anything up until an open-paren (`(`)
s/)$// substitute nothing for a close-paren (`)`) followed immediately by the end of a line
awk -F'(' '{print $NF}' file | sed 's/)//g'