在某个单词和最多提到的单词

时间:2017-03-30 13:15:38

标签: regex linux bash sed grep

所以我有file.txt就像这样

abc, def, class="my_name", this is good
def, hij, this is getting bad, and bad, class="my_class"
trying to achive my goal class="still_looking"

所以我需要一个类的值,即:

my_name
my_class
still_looking

我试过sed和grep但没有成功。

sed "s/[^class=]*,\([^\"]*\),^C/\1/" file.txt

grep -oP '(?<=class)[0-9][a-z][A-Z]+' file.txt

2 个答案:

答案 0 :(得分:2)

"字符串后捕获并输出所有非class="个字符:

sed 's/.*class="\([^"]*\)".*/\1/' file.txt

或每行多个class,使用grep:

grep -oP '(?<=class=")[^"]*' file.txt

答案 1 :(得分:0)

另一种变体:

grep -oP 'class="\K.*?(?=")'
相关问题