I hope I phrased the question correct. I have a script that makes use of 'sed' a lot. It works great on my ubuntu with the GNU 'sed'. But when I try to run it on BusyBox it fails. Is there a way to get the GNU sed on busybox? I am not a Linux pro.

  • Do you have sed installed in busybox?
    – jokerdino
    Oct 10 '12 at 12:05
  • 1
    1) What version of Busybox? 2) What errors/unexpected output are you getting? 3) Can you give us an example of a sed operation that works with GNU but not busybox? Oct 10 '12 at 13:46
  • 1
    1) BusyBox v1.19.4 2/3) This input {"expires": "Thu, 11 Oct 2012 11:30:29 +0000", "upload_id": "hhgJHflih753jDhhod", "offset": 293876} with sed -n -e 's/.*"upload_id":\s*"*\([^"]*\)"*.*/\1/p' gives the desired output (hhgJHflih753jDhhod) on my ubuntu but not on BusyBox
    – tzippy
    Oct 10 '12 at 15:23
  • BusyBox v1.29.3 (2021-01-17 01:25:00 PST) multi-call binary on ESXi: echo '{"expires": "Thu, 11 Oct 2012 11:30:29 +0000", "upload_id": "hhgJHflih753jDhhod", "offset": 293876}' | sed -n -e 's/.*"upload_id":\s*"*\([^"]*\)"*.*/\1/p' returns hhgJHflih753jDhhod. Apr 6 at 19:34

The Busybox iteself may have limited implementation of sed. You can copy the sed binary to some location and invoke it directly pointing it with a full path.

You may fix some incompatibility issues with replacing escapes that BusyBox builtin sed does not support, e.g. replacing the \s escape with [[:space:]] will solve the space-matching issue.

  • replace the \s escape with [[:space:]]. I think this will solve your problem
    – Serge
    Oct 10 '12 at 15:21
  • Thanks Serge ! Totally did the job! Although there are other locations in the script where replacing \s didnt help. If you post this as answer I'd be glad to accept it!
    – tzippy
    Oct 10 '12 at 15:34
  • @tzippy As you removed your comment with your regexp I just added a note to the answer.
    – Serge
    Oct 10 '12 at 15:44

You seem to misunderstand how busybox works. The tool is one single executable that acts in different ways depending on the name (or subcommand) with which it is called. If you call a symlink sed pointing to the busybox binary (or busybox sed), the "sed" functionality will be executed.

To get GNU sed into a busybox environment, you have to remove the sed symlink to busybox and provide a GNU sed binary and the libraries it depends on. You can identify the libraries with the ldd command:

$ ldd /bin/sed
    linux-gate.so.1 =>  (0xb7f78000)
    libselinux.so.1 => /lib/libselinux.so.1 (0xb7f56000)
    libc.so.6 => /lib/i686/cmov/libc.so.6 (0xb7e0f000)
    libdl.so.2 => /lib/i686/cmov/libdl.so.2 (0xb7e0a000)
    /lib/ld-linux.so.2 (0xb7f79000)
  • 2
    Oh I did not know that actually! Thanks for pointing it out!
    – tzippy
    Oct 10 '12 at 15:17
  • 1
    I just replaced the sed from busybox by downloading the sed package with opkg. this one appearently is the GNU sed.
    – tzippy
    Oct 10 '12 at 15:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.