Link to home
Start Free TrialLog in
Avatar of dinkarece
dinkarece

asked on

awk equivalent in busybox.

Hello,
I have an embedded linux box that has busybox. I have some scripts that use awk that I want to run on this embedded system. awk support is not implemented in my busybox and am looking for an equivalent of awk command to replace in my scripts.

I am enclosing utilities that are built in my busy box.

Any help is appreciated.

Thanks.



# busybox
BusyBox v0.60.5 (2006.02.07-22:24+0000) multi-call binary

Usage: busybox [function] [arguments]...
   or: [function] [arguments]...

        BusyBox is a multi-call binary that combines many common Unix
        utilities into a single executable.  Most people will create a
        link to busybox for each function they wish to use, and BusyBox
        will act like whatever it was invoked as.

Currently defined functions:
        [, ash, basename, busybox, cat, chgrp, chmod, chown, chroot, chvt,
        clear, cmp, cp, cut, date, dd, df, dirname, dmesg, du, echo, env,
        expr, false, find, free, freeramdisk, grep, gunzip, gzip, halt,
        head, hostname, id, ifconfig, init, insmod, kill, killall, klogd,
        linuxrc, ln, logger, ls, lsmod, md5sum, mkdir, mknod, modprobe,
        more, mount, mv, nc, pidof, ping, poweroff, printf, ps, pwd, reboot,
        rm, rmdir, rmmod, sed, sh, sleep, sort, stty, sync, tail, tar,
        tee, telnet, test, time, top, touch, tr, traceroute, true, tty,
        umount, uname, uniq, update, uptime, usleep, vi, watchdog, wc,
        which, whoami, xargs, yes, zcat
Avatar of ddunlea
ddunlea

Hi dinkarece,

awk is in the Editors sub menu of the busybox config. If you're using an embedded linux box, I presume you've built busybox yourself and can rebuld it with a new config? Or am I missing something?

Regards
Avatar of dinkarece

ASKER

Thanks for your quick reply.

No, I haven't built the busybox. I have a system that somebody else has built it and am trying to run scripts on that.

One of the statements that include awk include:

NODE_MAJOR=`awk "\\$2==\"$1\" { print \\$1 }" /proc/devices`


May be I should build the busybox myself with awk support if there is no other way.

Thanks.
ASKER CERTIFIED SOLUTION
Avatar of ddunlea
ddunlea

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for your reply.

Can somebody explain this statement:

`awk "\\$2==\"$1\" { print \\$1 }" /proc/devices`

I assume \\$2==\"$1\" is testing some condition. I understood the \ before " which is used to tell the shell that \"  \" is a separate string but I didn't understand about the preceeding of two \\ before $1 and $2. I tried to find the nitty details  of this \\ but couldn't find it on google.

Thanks for your help.
OK I guess now I have an understanding.

`awk "\\$2==\"$1\" { print \\$1 }" /proc/devices`

\\$2 is the second argument resulting from the awk command.

\"$1\" is the first argument on the command line.

\\$1 is the first argument resulting from the awk command.

So, \\ is used because it is enclosed in ` ` and if we don't enclose it in `` (while running from a command line), we just use \$1 instead of \\$1.

Thanks.
OK,
I figured it out without recompiling the busybox.

Basically, I was getting the major number for a particular module from /pro/devices/

Instead of awk, I can use

grep 'plxDrv' | cut -d ' ' -f1

That gives me what I want.

Thanks for your replies.