Andrew Tsay
Andrew Tsay

Reputation: 1953

How to escape a "." in awk?

For some reason a backslash doesn't work. This is for a file with delimited data.

Right now this is my expression is:

output=$(awk -F '|''BEGIN {count=0;} $2==Smith {count++; print count $1}' customer)

echo $output

gives me

11001 21002 31003

I want the output to look like:

1. 1001
2. 1002
3. 1003

This is my attempt..

awk -F '|''BEGIN {count=0;} $2==Smith {count++; print count, '\.', $1}' customer

Upvotes: 0

Views: 123

Answers (1)

Ander2
Ander2

Reputation: 5658

Print the statement with double quotes:

awk -F '|' 'BEGIN {count=0;} $2==Smith {count++; print count". "$1}' customer

Upvotes: 4

Related Questions