Unix/Linux: Find all files that contain multiple strings/patterns

When using Unix or Linux, if you ever need to find all files that contain multiple strings/patterns, — such as finding all Scala files that contain 'try', 'catch', and 'finally' — this find/awk command seems to do the trick:

find . -type f -name *scala -exec awk 'BEGIN {RS=""; FS="\n"} /try/ && /catch/ && /finally/ {print FILENAME}' {} \;

As shown in the image, all of the matching filenames are printed out. As Monk says, you’ll thank me later. :)

(I should mention that I got part of the solution from this page.)

Scala: How to extract parts of a String that match regex patterns

This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 1.9, “Extracting Parts of a String that Match Patterns.”


You want to extract one or more parts of a Scala String that match the regular-expression patterns you specify.


Define the regular-expression (regex) patterns you want to extract, placing parentheses around them so you can extract them as “regular-expression groups.” First, define the desired pattern:

How to find regex patterns in Scala strings

This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 1.7, “Finding Patterns in Scala Strings.”


You need to determine whether a Scala String contains a regular expression pattern.

A custom TextMate command that uses ‘sed’

In this post I share the contents of a custom TextMate command I just created that uses pandoc and sed to convert markdown content in the TextMate editor to a “pretty printer” version of HTML:



# note: 'sed -E' gives you the advanced regex's

# use pandoc to convert from markdown to html,
# then use sed to clean up the resulting html
pandoc -f markdown -t html |\
sed -Ee "/<p|<h2|<h3|<h4|<aside|<div|<ul|<ol/i\\

You can try to use a command like tidy to clean the HTML, but the version of tidy I have does not know about HTML5 tags. The TextMate Markdown plugin also doesn’t work the way I want it. Besides that, I’m trying to learn more about writing TextMate commands anyway.

As an important note, when you set this up as a TextMate command and then run it, it will convert the TextMate editor contents from markdown to HTML.

(In a related note, is also a good resource for TextMate command and bundle documentation.)

In summary, this code shows:

* How to execute a Unix shell command from TextMate
* Specifically, how to execute a sed command from TextMate
* How to use modern regular expressions with sed (the -E option)
* How to search for multiple regex search patterns with sed

The Mediator Design Pattern in Java

Summary: The Mediator Design Pattern is demonstrated in a Java example (a Java Mediator Pattern example).

Android UI design guidelines links

Google has a nice Android UI design guidelines section on the Android website. As I'm working on a new Android tablet application, I keep looking back at this section, and these are the most relevant pages for me:

Design Patterns in Java

I've recently started writing a series of articles on Design Patterns in Java, i.e., Design Patterns explained using Java source code examples. Although it will take me a little while to create each design pattern example, this page will eventually contain links to all of those examples.

If you're not familiar with software design patterns, they're described on Wikipedia like this:

Chain of Responsibility Pattern in Java

The Chain of Responsibility Pattern is a design pattern whose intent is to avoid coupling the sender of a request to its receivers by giving more than one object a chance to handle a request. The Chain of Responsibility works like this:

A Java "extract method" refactoring example

Summary: A Java "extract method" refactoring example is demonstrated.

If you don't own a copy of Martin Fowler's Refactoring book, I highly recommend it. The basic idea of refactoring source code is that the code "smells" in one way or another, and there are a variety of ways to improve smelly code. More specifically, Mr. Fowler describes refactoring as this: