Hi I'm new to using sed

When I type:

echo day | sed /s/day/night/

the output is:


In other words, it just appends the entire line after the substitution. I am using a Samsung Galaxy Tab A, running Android 6.01. When I type which sed I get /system/bin/sed and when I type sed --version I get This is not GNU sed version 9.0.

I saw a couple posts about this already online. And people were saying this might be a buggy version of sed. Are there any other ways to do search and replace in shell scripts (or just an automated fashion) on an android tablet?

I installed something called "busybox" which provides something called ed, but again, I was having problems doing the substitution command. It would work sometimes, but other times it would say "no substitutions found for ___ (short, basic regex statement I got from a book which is supposed to be compatible with all versions of regex - okay, that sounds vague here's the regex statement: ^.*\bthe\b.*$ (The file contains lots of "the" words.)

I guess my options are: A) try to install linux onto this tablet, B) don't use the tablet at all, C) keep looking for software that will do automated search and replaces on the tablet or try to identify what the bug is in sed and if there's a special code word it needs to work right, D) ?

EDIT: Added info per request: When I typed

echo day | od -c

I got

37777776620   d   a   y   \n

When I typed

echo day | sed 's/day/night/' | od -c

I got

37777776620   n   i   g   h   t   \0   d   a   y   \n

I hear you on the copy and paste recommendation, but I couldn't seem to do copy or paste in this "terminal emulator" app.

  • Did enclose the sed statement in quotes? so echo day | sed 's/day/night/' – Raman Sailopal Nov 21 '17 at 16:17
  • I just tried it with the single quotes, on the command line. same response: "nightday" (I had it reversed in my original post but I just fixed it, sorry have a sore throat today and can't think straight...) – Edward Nov 21 '17 at 16:21
  • That should have given a syntax error. Does this work: echo day | sed 's/day/night/' ? – terdon Nov 21 '17 at 16:29
  • I tried it again with the single quotes: echo day | sed 's/day/night/' and the response was: nightday This is also the kind of behavior I experienced when trying to put sed commands in a sh script. – Edward Nov 21 '17 at 16:34
  • Wait a second. Please edit your question and post the output of: echo day | od -c and echo day | sed 's/day/night/' | od -c. Copy/paste directly if at all possible. – terdon Nov 21 '17 at 16:37

Your Answer

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

Browse other questions tagged or ask your own question.