You have mucked up your quotes and syntax. To set the input field separator, the easiest way to do it is with the -F
option on the command line:
awk -F '[0-9]' '{ print $1 }'
or
awk -F '[[:digit:]]' '{ print $1 }'
This would use any digit as the input field separator, and then output the first field from each line.
The [0-9]
and [[:digit:]]
expressions are not quite the same, depending on your locale. See "Difference between [0-9], [[:digit:]] and \d".
One could also set FS
in the awk
program itself. This is usually done in a BEGIN
block as it's a one-time initialisation:
awk 'BEGIN { FS = "[0-9]" } { print $1 }'
Note that single quotes can't be used in a single-quoted string in the shell, and that awk
strings always use double quotes.