We help IT Professionals succeed at work.

awk equivalent in busybox.

dinkarece
dinkarece asked
on
Medium Priority
1,992 Views
Last Modified: 2012-06-27
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
Comment
Watch Question

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

Author

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.

Thanks.
Commented:
Building busybox is very easy, so it may well be worth your while. Sorry I can't be of any more help.

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

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.

Author

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.

Thanks.

Author

Commented:
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.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.