正規表現 python vs shellscript


置換表現

問題1

内容1
python.py
s = '[email protected] [email protected] [email protected]'

print(re.sub('[a-z]*@', 'ABC@', s))
shell.sh
#  mail.text に'[email protected] [email protected] [email protected]'を記入して

# その1
sed -e  "s/*@/ABC@/g" mail.txt  

# その2
sed -e  "s/[a-z]*@/ABC@/g" mail.txt  

問題2

内容2
以下の「文章」を単語区切りにしたい.
'Now I need a drink, alcoholic of course, after the heavy lectures involving quantum mechanics.'
python.py
str = 'Now I need a drink, alcoholic of course, after the heavy lectures involving quantum mechanics.'

# ,と.を除去
str = re.sub('[,\.]', '', str)  
shell.sh
# memo.textに「文章」を記入して

sed -e  "s/\.//g"  -e  "s/\,//g" memo.txt