在Linux上匹配单词时返回整行?

问题描述 投票:-1回答:2

嘿,我有一个看起来像这样的CSV文件:

ID,Page_Number,Subject,Description,Upvotes
1,3,Fruit", An apple", 5
2,3,"School","The yellow Banana",8
3,4,"Restaurant","The red apple",4
4,5,"School","The big apple",5
5,5,"Apple","Great for a snack",5

因此,我想搜索包含单词apple的所有行,无论它是否在主题或描述列中并返回所有行都无所谓。我应该使用AWK命令吗?

结果应该是:

ID,Page_Number,Subject,Description,Upvotes
1,3,Fruit", An apple", 5
3,4,"Restaurant","The red apple",4
4,5,"School","The big apple",5
5,5,"Apple","Great for a snack",5
linux shell csv ubuntu
2个回答
0
投票

有很多方法。试试这个

grep -i 'apple'  file
sed '/\<apple\>/I! d' file
awk '{IGNORECASE=1}/apple/{print}' file

0
投票

希望这会有所帮助。

awk 'BEGIN{IGNORECASE=1}; NR==1 {print}; /[Aa]pple/ {print}' filename
© www.soinside.com 2019 - 2024. All rights reserved.