sed grep awk 正则表达式

1
2
3
4
5
6
7
8
9
10
# regular_express.txt

echo "Love your parents. We are too busy growing up yet we forget that they are already growing old——多关心一下自己的父母吧,我们总忙着自己成长,却忘了他们也在变老。
The moment you think about giving up,think of the reason why you held on so long——每当你想放弃的时候,想一想是什么支撑着你一路坚持。
I don't wanna be your 'number one' that implies there are a number two and maybe a number three. I want to be your only one——我不想做你的“第一”,因为那就意味着还有第二,第三……我只想做你的“唯一”。
Total umbrella for someone else if he, you're just not for him in the rain.——如果他总为别人撑伞,你又何苦非为他等在雨中。
Hold my hand,you won't get lost even with eyes closed. ——握住我的手,即使你閉上眼睛也不會迷路。
We never really grow up. We only learn how to act in public. ——我们从未真正长大,我们只是在别人面前学会了假装。
Each trauma, is another kind of maturity. ——每一种创伤,都是另一种成熟。
Fortune favours the brave——运气往往眷顾勇敢的人。" > regular_express.txt

sed regex

1
echo "Love your parents. We are too busy growing up yet we forget that they are already growing old——多关心一下自己的父母吧,我们总忙着自己成长,却忘了他们也在变老。 \n\nThe moment you think about giving up,think of the reason why you held on so long——每当你想放弃的时候,想一想是什么支撑着你一路坚持。 \n\nI don't wanna be your 'number one' that implies there are a number two and maybe a number three. I want to be your only one——我不想做你的“第一”,因为那就意味着还有第二,第三……我只想做你的“唯一”。 \n\nTotal umbrella for someone else if he, you're just not for him in the rain.——如果他总为别人撑伞,你又何苦非为他等在雨中。 \n\nHold my hand,you won't get lost even with eyes closed. ——握住我的手,即使你閉上眼睛也不會迷路。 \n\nWe never really grow up. We only learn how to act in public. ——我们从未真正长大,我们只是在别人面前学会了假装。 \n\nEach trauma, is another kind of maturity. ——每一种创伤,都是另一种成熟。\n\nFortune favours the brave——运气往往眷顾勇敢的人。" | sed -E -ne 's/\\n\\n/\'$'\n/g' -e "p"

grep regex

1
grep -E -e "\b[a-z]{5}\b" regular_express.txt

awk regex

1
awk '/[a-z]{5}/{print FILENAME,NR,$0}' $file | grep -E "[a-z]{5}"