refresh
refresh

Reputation: 1329

Linux awk command with pipe

Can anyone tell me what the below linux command does:

tail -5 test.log | grep 'Start Calculate' | awk '{print $1}'

I know tail -5 test.log | grep 'Start Calculate' looks for the 5 last lines containing 'Start Calculate' in test.log. But then I don't get what awk does?

Upvotes: 1

Views: 7676

Answers (2)

Carlos Campderrós
Carlos Campderrós

Reputation: 22972

the awk command is printing the first whitespace-separated field of each line.

Upvotes: 0

meucaa
meucaa

Reputation: 1515

tail -5 test.log take the 5 last lines of the test.log file

then

grep 'Start Calculate' filter to keep only the lines containing 'Start Calculate'

then

awk '{print $1}' take the first column of each line (using space as the separator between columns)

Upvotes: 3

Related Questions