2
我有ID的列表的文件如下grep的每一行
OG1: apple|fruits_1 cucumber|veg_1 apple|fruits_1 carrot|veg_2
OG2: apple|fruits_5 cucumber|veg_1 apple|fruits_1 pineapple|fruit_2
OG3: cucumber|veg_1 apple|fruits_9 carrot|veg_2
OG4: apple|fruits_3 cucumber|veg_1 apple|fruits_4 pineapple|fruit_7
OG5: pineapple|fruit_2 pineapple|fruit_2 apple|fruits_1 pineapple|fruit_2
OG6: apple|fruits_5 apple|fruits_1 apple|fruits_6 apple|fruits_7
現在,我想提取蘋果的第一次出現第一次出現|在每一行,給我
OG1: apple|fruits_1
OG2: apple|fruits_5
OG3: apple|fruits_9
OG4: apple|fruits_3
OG5: apple|fruits_1
OG6: apple|fruits_5
我試圖
grep -w -m 1 "apple" sample.txt
只給了我
OG1: apple|fruits_1 cucumber|veg_1 apple|fruits_1 carrot|veg_2