Velvet Star Monitor

Standout celebrity highlights with iconic style.

general

grep for pattern including carriage return on a Mac

Writer Sophia Terry

I want to search files for colon followed by carriage return followed by dash. I am using macOS (so it's BSD grep).

I would have thought

grep -l ":\n-" filename-pattern

would work, but it doesn't! And using

grep -l ":\n-" filename-pattern

doesn't work either.

Here's the octal dump of the line in question:

0000020 U R D A T A B A S E : \n - T

Other posters have noted that since grep is line oriented, I will need to use awk, but I can't seem to get the pattern right - I am using

awk '/:\n- /' filename

1

1 Answer

Like Gordon said grep won't be able to match multiline statements, but awk will be able to. Here is another question that will hopefully help you build the proper statement that you are looking for. Good luck!

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy