I'm trying to extract lines from a subtitle (.srt) file. When I grep for a specific line number, I get the answer I expect:
% grep -e "^817" ponyo.srt
817
%
but when I try to grep for that line including a carriage return (or a carriage return and EOL), I get a blank line:
% grep -e "^817\r" ponyo.srt
% grep -e "^817^M$" ponyo.srt
%
Here's the text file using "cat -e" to show hidden characters:
% cat -e ponyo.srt
1^M$
00:04:38,478 --> 00:04:43,381^M$
The Beginning^M$
^M$
2^M$
00:04:44,751 --> 00:04:51,122^M$
PONYO ON THE CLIFF BY THE SEA^M$
^M$
474^M$
01:00:23,016 --> 01:00:25,041^M$
Stay here with Ponyo.^M$
^M$
475^M$
01:00:25,285 --> 01:00:28,618^M$
I'm going too.^M$
Let's take Ponyo with us.^M$
^M$
817^M$
01:40:08,532 --> 01:40:13,834^M$
<i>Oh he 's my favorite little boy</i>^M$
^M$
823^M$
01:40:32,456 --> 01:40:38,156^M$
Studio Ghibli^M$
^M$
824^M$
01:40:39,530 --> 01:40:42,624^M$
The End^M$
^M$
825^M$
01:40:42,766 --> 01:40:45,792^M$
English translation by^M$
Jim Hubbert and Rieko Izutsu-Vajirasarn^M$
English subtitles by^M$
Aura^M$
^M$
%
How can I grep for the end of lines and get the whole line in the results?
EDIT: To add, just searching for EOL returns nothing, as I would expect:
% grep -e "^817$" ponyo.srt
%
mac2unix
on the file before attempting to work with it. – jesse_b Feb 02 '22 at 01:49grep
aliased to something that includes a--color=
specification? – steeldriver Feb 02 '22 at 01:52$
matches to end of line, no need for trying to match\r
or\n
– jsotola Feb 02 '22 at 02:01\n
, not CR\r
, so matching$
may not be what you expect. – U. Windl Feb 08 '22 at 14:10