Eu estou lendo um livro de regular expressions em que o autor utiliza egrep
para mostrar alguns exemplos. Ocorre que quando tento replicar os exemplos no meu computador meu output fica diferente do apresentado no livro. No meu caso, o output do egrep
é o texto completo, com os matchs da regex destacados em vermelho. Por outro lado, o autor, que usa o mesmo comando, tem como output a lista de matchs.
Exemplo:
egrep '\bS[a-z]+' bezos.txt
Output:
Bezos was born Jeffrey Preston Jorgensen in Albuquerque, New Mexico, on January 12, 1964, the son of Jacklyn (née Gise) and Ted Jorgensen.[9] At the time of his birth, his mother was a 17-year-old high school student and his father was a bike shop owner.[10] After his parents divorced, his mother married Cuban immigrant Miguel "Mike" Bezos in April 1968.[11] Shortly after the wedding, Mike adopted four-year-old Jorgensen, whose surname was then changed to Bezos.[12] The family moved to Houston, Texas, where Mike worked as an engineer for Exxon after he received a degree from the University of New Mexico.[13] Bezos attended River Oaks Elementary School in Houston from fourth to sixth grade.[14] Bezos's maternal grandfather was Lawrence Preston Gise, a regional director of the U.S. Atomic Energy Commission (AEC) in Albuquerque.[15] Gise retired early to his family's ranch near Cotulla, Texas, where Bezos would spend many summers in his youth.[13] Bezos would later purchase this ranch and expand it from 25,000 acres (10,117 ha) to 300,000 acres (121,406 ha).[16][17] His maternal grandmother was Mattie Louise Gise (née Strait), through whom he is a cousin of country singer George Strait.[18]
No output as palvras Shorlty, School e Strait aparecem no terminal em vermelho.
O mesmo comando, no livro, teria o seguinte output:
Shortly
School
Strait
Como faço para printar apenas a lista de matchs, como no livro, e não o texto inteiro?
P.S: No livro, o autor usa uma arquivo de extensão list
. Talvez isso ajude a explicar a diferença no output, mas nunca vi essa extensão de arquivo antes, por isso fiquei em dúvida se era extensão mesmo ou apenas o nome de exemplo do arquivo.