私のファイルには次のような行があります。
This is one word1:word2 of the lines
This is another word3:word4 of the lines
Line without a match
Yet another line word5:word6 for test
:
前後の単語をgrepして返す必要があります:
。
上記の行をgrepingして得なければならない出力は次のとおりです。
word1:word2
word3:word4
word5:word6
ベストアンサー1
GNUの使用grep
:
start cmd:> echo "This is one word1:word2 of the lines" |
grep -Eo '[[:alnum:]]+:[[:alnum:]]+'
word1:word2
start cmd:> echo "This is one wordx:wordy of the lines" |
grep -Eo '[[:alpha:]]*:[[:alpha:]]*'
wordx:wordy
start cmd:> echo "This is one wo_rdx:wo_rdy of the lines" |
grep -Eo '[[:alpha:]_]*:[[:alpha:]_]*'
wo_rdx:wo_rdy