dhruvbird
dhruvbird

Reputation: 6189

how do I use pipes in a makefile shell command?

I have the following code snippet in a Makefile which always fails unless I remove the references to sed & grep below.

TAB=$(shell printf "\t")
all: abstract.tsv
      $(shell cut -d "${TAB}" -f 3 abstract.tsv | sed "s/^\s*//" | \
        sed "s/\s*$//" | grep -v "^\s*$" | sort -f -S 300M | \
        uniq > referenced_images.sorted.tsv)

This is the error I get:

/bin/bash: -c: line 0: unexpected EOF while looking for matching `"'
/bin/bash: -c: line 1: syntax error: unexpected end of file

What could be wrong?

Upvotes: 24

Views: 34011

Answers (1)

William Pursell
William Pursell

Reputation: 212298

One error is coming from sed. When you write:

sed "s/\s*$//"

make expands the variable $/ to an empty string, so sed is missing a delimiter. Try:

sed "s/\s*$$//"

Using $" is causing the same problem in grep. Use grep -v "^\s*$$" instead.

Upvotes: 36

Related Questions