I'm new to the forum so please forgive any syntactical errors in my question.
I'm trying to replace spaces with underscores in a matched substring only. I figured sed would be the best editor for this but I cannot find the proper code to do this.
Sample line from file1 below:
Some text before pattern to match href="./Dynamic Directory name - Junk_files/irrelevant stuff after match">
Would like to change to this:
Some text before pattern to match href="./Dynamic_Directory_name_-_Junk_files/irrelevant stuff after match">
I thought I was close with this cat file1 |sed '/\.\/.*. Junk_files/ { s/ /_/g; }'
but all it did was replace all spaces on the matched line with underscores.
Any help with this would be greatly appreciate. Thanks
sed
solution, but you're clearly unsatisfied with the answers. That's becausesed
(and other text-processing tools) are extremely limited when it comes to parsing HTML. You might want to add more examples, remove thesed
tag and ask for a solution which won't necessarily have to involvesed
or other text-processing tools.