Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to use regex as a field seperator in awk. From my reading this seems possible but I can't get the syntax right.

rpm -qa | awk '{ 'FS == [0-9]' ; print $1 }'
awk: cmd. line:1: { FS
awk: cmd. line:1:     ^ unexpected newline or end of string

Thoughts? The goal if not obviouse is to get a list of software without version number.

share|improve this question
up vote 14 down vote accepted

You have mucked up your quotes. Here's a better way:

awk -F'[0-9]' '{ print $1 }'
share|improve this answer

+1 for KAK's answer. Alternately, the FS variable can be set in the BEGIN block:

awk 'BEGIN {FS="[0-9]"} {print $1}'

Changing FS in a action block won't take effect until the next line is read

$ printf "%s\n" "abc123 def456" "ghi789 jkl0" | awk '{FS="[0-9]"; print $1}'

The other errors in the question:

  • can't use single quotes inside a single-quoted string
  • == is a comparison operator, = is for variable assignment
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.