Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
シェル スクリプトを使用して、特定の文に含まれるすべてのハッシュタグを簡単に抽出する方法を教えてください。
例 'This is a #test that will #allow me to #remove stuff':#test #allow #remove
'This is a #test that will #allow me to #remove stuff'
#test #allow #remove
awkで代替手段を提供するだけです:
awk '{for (i=1; i<=NF; i++) if ($i ~ /^#/) print $i}'
そして、これらの数学を抽出する純粋な BASH の方法は次のとおりです。
x=$str # your original string while :; do if [[ $x =~ (\#[a-z]+)(.*)$ ]]; then echo "${BASH_REMATCH[1]}" x="${BASH_REMATCH[2]}" else break fi done