У меня есть файл со списком идентификаторов следующего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