Reputation: 23794
Is it possible to reference the field separator FS
in a regular expression of awk
as it is possible in the body of an expression?
awk -F: '/^FS/{print FS}'
Upvotes: 2
Views: 495
Reputation: 74596
You can't use any variable inside / /
- FS
is no exception.
Your script could be written using ~
which allows you to convert a string into a regular expression:
awk -F: '$0 ~ "^" FS { print FS }'
Upvotes: 6
Reputation: 157947
When the field separator is at the first column of the line, NF
must be greater than 1
and the first field have a length of zero:
awk -F: 'NF>1 && !(length($1)) {print FS}'
Upvotes: 1