• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1394
  • Last Modified:

awk equivalent in busybox.

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.


# 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
  • 4
  • 2
1 Solution
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?

dinkareceAuthor Commented:
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.

Building busybox is very easy, so it may well be worth your while. Sorry I can't be of any more help.
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

dinkareceAuthor Commented:
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.
dinkareceAuthor Commented:
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.

dinkareceAuthor Commented:
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.

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now