> On Wed, May 26, 2010 at 9:59 PM, Alexander Eremin > <[email protected]> wrote: > >> I'm not a nawk expert, but I'll take you up on the > >> challenge. I've got > >> this so far: > >> > >> /usr/bin/nawk '$1 ~ /ramdisk/ {print $2}' > >> </etc/mnttab > >> > >> but I'm not sure how to do the regular expression > for > >> $2 being ^/$. Doing > >> > >> /usr/bin/nawk '$1 ~ /ramdisk/, $2 ~ /^\/$/ {print > >> $2}' </etc/mnttab > >> > >> doesn't work. It matches anything where $2 has a > / > >> anywhere. Any hints? > >> > > For example > > /usr/bin/nawk '$1 ~ /ramdisk/ {if ($2 ~ /^\/$/) > print $2}' </etc/mnttab > > Thanks... > ... example below: > -- snip -- > cat <<EOF >'zzz' > /dev/dsk/c1t0d0s0 / ufs rw,intr,largefiles,logging,xat > tr,onerror=panic,dev=800000 1273684894 > /devices /devices devfs dev=6400000 1273684882 > /dev /dev dev dev=6440000 1273684882 > ctfs /system/contract ctfs dev=6480001 1273684882 > proc /proc proc dev=64c0000 1273684882 > mnttab /etc/mnttab mntfs dev=6500001 1273684882 > swap /etc/svc/volatile tmpfs xattr,dev=6540001 1273684 > 882 > objfs /system/object objfs dev=6580001 1273684882 > sharefs /etc/dfs/sharetab sharefs dev=65c0001 12736848 > 82 > /platform/sun4u-us3/lib/libc_psr/libc_psr_hwcap1.so.1 > /platform/sun4u-us3/lib/libc_psr.so.1 lofs dev=800000 > 1273684890 > /platform/sun4u-us3/lib/sparcv9/libc_psr/libc_psr_hwca > p1.so.1 /platform/sun4u-us3/lib/sparcv9/libc_psr.so.1 > lofs dev=800000 1273684890 > fd /dev/fd fd rw,dev=6700001 1273684894 > swap /tmp tmpfs xattr,dev=6540002 1273684895 > swap /var/run tmpfs xattr,dev=6540003 1273684895 > -hosts /net autofs nosuid,indirect,ignore,nobrowse,dev > =67c0001 1273684909 > auto_home /home autofs indirect,ignore,nobrowse,dev=67 > c0002 1273684909 > /export/home/test001 /home/test001 lofs dev=800000 127 > 3685096 > /export/home/fleyta /home/fleyta lofs dev=800000 12747 > 71727 > jupiterb48:/export/home/gisburn /home/gisburn nfs xatt > r,dev=6780003 1274807526 > /devices/ramdisk:a / ufs > rw,intr,largefiles,logging,xattr,onerror=panic,dev=118 > 0001 1274892503 > /dev/dsk/c1t0d0s0 / ufs rw,intr,largefiles,logging,xat > tr,onerror=panic,dev=800000 1273684894 > /devices /devices devfs dev=6400000 1273684882 > /dev /dev dev dev=6440000 1273684882 > ctfs /system/contract ctfs dev=6480001 1273684882 > proc /proc proc dev=64c0000 1273684882 > mnttab /etc/mnttab mntfs dev=6500001 1273684882 > swap /etc/svc/volatile tmpfs xattr,dev=6540001 1273684 > 882 > objfs /system/object objfs dev=6580001 1273684882 > sharefs /etc/dfs/sharetab sharefs dev=65c0001 12736848 > 82 > /platform/sun4u-us3/lib/libc_psr/libc_psr_hwcap1.so.1 > /platform/sun4u-us3/lib/libc_psr.so.1 lofs dev=800000 > 1273684890 > /platform/sun4u-us3/lib/sparcv9/libc_psr/libc_psr_hwca > p1.so.1 /platform/sun4u-us3/lib/sparcv9/libc_psr.so.1 > lofs dev=800000 1273684890 > fd /dev/fd fd rw,dev=6700001 1273684894 > swap /tmp tmpfs xattr,dev=6540002 1273684895 > swap /var/run tmpfs xattr,dev=6540003 1273684895 > -hosts /net autofs nosuid,indirect,ignore,nobrowse,dev > =67c0001 1273684909 > auto_home /home autofs indirect,ignore,nobrowse,dev=67 > c0002 1273684909 > /export/home/test001 /home/test001 lofs dev=800000 127 > 3685096 > /export/home/fleyta /home/fleyta lofs dev=800000 12747 > 71727 > jupiterb48:/export/home/gisburn /home/gisburn nfs xatt > r,dev=6780003 1274807526 > EOF > > # read file into variable "input" > input="$( < 'zzz' )" > > # pick the data, \3 refers to the content matched by > the pattern in > the 3rd ()-bracket pair > match="${input/~(Elr-g).*([^[:space:]]*ramdisk[^[:spac > e:]]*)([[:space:]]+)([^[:space:]])([[:space:]]+).*/\3} > " > > if [[ $match != "$input" ]] ; then > printf 'match is %q\n' "$match" > else > print -u2 'no match found.' > fi > -- snip -- > > The core in this example is the line... > -- snip -- > ${input/~(Elr-g).*([^[:space:]]*ramdisk[^[:space:]]*)( > [[:space:]]+)([^[:space:]])([[:space:]]+).*/\3} > -- snip -- > It grabs the value of variable "input" and returns > the content which > matches the extended regular pattern (that does the > ~(Elr-g) specify: > Extended regular pattern ("E") with left ("l") and > right ("r")anchors > and greedy matching ("-g", the greedy mode matches > the shortest > pattern, the default for regular expressions is to > match the longest > character sequence)) in the 3rd bracket pair. If no > match is found the > full value of variable "input" is returned. > > Notes: > 1.I made the example a bit more verbose, AFAIK the > [:space:] can be > replaced with a plain white space assuming > /etc/mnttab doesn't use > both SPACE and TAB in the same file. > 2. [^ ] means: This pattern matches a single > character which is not a > space (^ means "not") > 3. * matches zero or more characters and + matches > one or more characters > ---- > > Bye, > Roland > > -- > __ . . __ > o.\ \/ /.o) [email protected] > \__\/\/__/ MPEG specialist, C&&JAVA&&Sun&&Unix > programmer > /O /==\ O\ TEL +49 641 3992797 > (;O/ \/ \O;) > _______________________________________________ > caiman-discuss mailing list > [email protected] > http://mail.opensolaris.org/mailman/listinfo/caiman-di > scuss >
Exellent, because do not need a call external cmd ) Thanks, Roland! Alex -- This message posted from opensolaris.org _______________________________________________ caiman-discuss mailing list [email protected] http://mail.opensolaris.org/mailman/listinfo/caiman-discuss

