Skip to content
Advertisement

Replace white spaces with underscores within a file (bash)

I am currently writing a script that accesses another file using “mapfile” to put it into an array. However, the inputted file contains some white spaces, which the script reads as a new array entry.

How do I replace the white spaces with underscores within the body of the file I’m bringing in? I have only seen instructions for how to replace a file name, not what’s within it.

Thank you in advance! Please let me know if you need any further clarification.

Advertisement

Answer

Given:

JavaScript

You can use sed:

JavaScript

So then you can do:

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement