0

I'm trying to run the sed command in bash but it keeps giving me errors, I don't know what I did wrong.

This is the code: $sed 's/unix/linux/' geekfile.txt and this is the error message: bash: s/unix/linux/: No such file or directory.

I tried adding -i and it told me the command is not found. I don't know what to do. Here is a screenshot of what I am facing:

enter image description here

5
  • 1
    could you provide your example script? make sure not to use eval.
    – tatsu
    Jun 12, 2019 at 8:27
  • It's treating your script part of the command 's/unix/linux' as a file input which is strange. Is there anything between the sed and the 's/unix/linux' bit.
    – Arronical
    Jun 12, 2019 at 8:40
  • 3
    I suspect you are including the $ (which is meant to represent the shell prompt) - this causes the shell to expand $sed as a (presumably empty) variable, and then your command is becoming 's/unix/linux/' geekfile.txt instead of sed 's/unix/linux/' geekfile.txt Jun 12, 2019 at 8:44
  • 1
    @steeldriver this is definitely what's happening, the screenshot hidden until the suggested edit bears this out.
    – Arronical
    Jun 12, 2019 at 8:58
  • @steeldriver that was truly the problem, it works now. thank you.
    – Gweeks
    Jun 12, 2019 at 9:42

1 Answer 1

1

works fine :

user@pc:~$ cat geekfile.txt 
unix 
mal
lala
unix 
oh
user@pc:~$ sed -i 's/unix/linux/' geekfile.txt
user@pc:~$ cat geekfile.txt 
linux 
mal
lala
linux 
oh

just don't include the $ sign that's part of the terminal output, not part of the command.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .