Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use awk in Makefile?

I hava a Makefile which needs to extract some information from a textfile `someText.txt by using awk. Here is an example:

Executing awk on my textfile manually in the console works pretty fine:

$ cat someText.txt | awk '/Total number:/ {print $NF}'
$ 42

But using it in my makefile does not work:

MYVAR=$(shell cat someText.txt | awk '/Total number:/ {print $NF}')
all:
    @echo Count: $(MYVAR)

The output is: Count:

But I would suggest the output is Count: 42

like image 469
eDeviser Avatar asked Sep 13 '25 09:09

eDeviser


1 Answers

MYVAR=$(shell awk '/Total number:/ {print $$NF}' someText.txt)

like image 52
田咖啡 Avatar answered Sep 14 '25 23:09

田咖啡