所以我有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
答案 0 :(得分:2)
在"
字符串后捕获并输出所有非class="
个字符:
sed 's/.*class="\([^"]*\)".*/\1/' file.txt
或每行多个class
,使用grep:
grep -oP '(?<=class=")[^"]*' file.txt
答案 1 :(得分:0)
另一种变体:
grep -oP 'class="\K.*?(?=")'