6

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.

tzippy
  • 454
  • 3
  • 8
  • 18
  • Do you have sed installed in busybox? – jokerdino Oct 10 '12 at 12:05
  • 2
    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? – RI Swamp Yankee 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`. – Jeroen Wiert Pluimers Apr 06 '21 at 19:34

2 Answers2

6

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.

Serge
  • 2,735
  • 12
  • 17
  • 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
2

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)
Ansgar Wiechers
  • 5,400
  • 2
  • 21
  • 23