Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

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 have a string like this

TEST="/dev/sda1 on /media/sda1 type vfat (rw,relatime,fmask=0000,dmask=0000,allow_utime=0022,codepage=cp437,iocharset=iso8859-1,quiet)"

(Result from mount | grep sda1)

where I want to match the mount point. My regex (adopted from here) is

(?<=on[ \t])(.*)(?=[ \t]type)

But for some reasons it doesn't work for me with several tools (Busybox ash 1.14.2):

echo $TEST | grep -o -e '(?<=on[ \t])(.*)(?=[ \t]type)'

Gives me no result.

echo $TEST | awk 'match($0, /(?<=on )(.*)(?= type)/){print $0}'

Returns an error awk: bad regex '(?<=on[ ])(.*)(?=[ ]type)': Invalid preceding regular expression

expr match "$TEST" '\(?<=on[ \t]\)\(.*\)\(?=[ \t]type\)'

Also returns an empty result.

I feel kinda stupid.

share|improve this question
Why don't you just try to match on (.*) type? – lgeorget Apr 22 '14 at 13:25
Note also that if you want the third field of a line, awk can give it to you for free: echo $TEST | awk '{print $3}'. – lgeorget Apr 22 '14 at 13:29
AFAIK blank is also a valid character for an USB device so this would break this code. Otherwise I could use echo $TEST | cut -d' ' -f3 – Noir Apr 22 '14 at 13:34
up vote 7 down vote accepted

Lookarounds are perl regex features. GNU grep implements them (with the -P option). I cannot say whether any busybox command does.

In this case though, you're just looking for the work after "on". Choose one of

echo "$TEST" | awk '{for (i=1; i<=NF; i++) if ($i == "on") {print $(i+1); break}}'
echo "$TEST" | sed 's/.*on[[:blank:]]\(.*\)[[:blank:]]type.*/\1/'
share|improve this answer
Thank you very much! I'm using the SED code. – Noir Apr 22 '14 at 14:08

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.