question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

sed can't replace files in a different directory

See original GitHub issue

shx version: 0.3.2 npm version: 6.9.0 node version: 10.16.0

I’m trying to replace some text for a file in a child folder /docs.

I run this command:

shx sed -i 's/globals.html/index.html/g' docs/index.html

And get the error: sed: no files given

I’ve confirmed this works with the vanilla unix sed command. Steps to reproduce:

  1. git clone https://github.com/crhistianramirez/shx-bug-repro-sed.git
  2. cd shx-bug-repro-sed
  3. npm install
  4. npm run bug

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
nfischercommented, Dec 9, 2019

Following up here to summarize the discussion, for future reference. Be careful with single quotes. Windows and unix treat single quotes differently and there’s no way for shx to workaround this. Prefer double quotes instead when possible, even if that means escaping double quotes inside package.json.

1reaction
nfischercommented, Aug 27, 2019

Ah I see, this is in package.json like so:

{
  "scripts": {
    "foo": "shx sed -i \"s/globals.html/index.html/g\" docs/index.html"
  }
}

Now I see the appeal of single quotes, although I think we’ve found those don’t work.

For your specific case, you can omit quotes entirely:

    "foo": "shx sed -i s/globals.html/index.html/g docs/index.html"

But in general, yeah this is something we might document.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Performing a recursive find and replace with sed only changes ...
I am trying to recursively search the current directory, performing a sed replace on the first line of each .txt file found.
Read more >
replace | Microsoft Learn
Reference article for the replace command, which can replace existing or add new files to a directory.
Read more >
using sed to replace a string in files which are in different folders
I want to write a script which goes to each folder and replace a string(in the file *.mvw) "D3PLOT_1DForce" with the name of...
Read more >
Sed doesn't take file to work at - Super User
This will cause sed to replace instances where string1 is at the beginning of the line with the string string2 for all files...
Read more >
Replace Files , Skip, Let Me Decide. Windows 10 Solved
In Microsoft Windows 10, when you try to organize files, you will sometimes be surprised at the lack of options. You might even...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found