4
votes
2answers
134 views

Replace very long string in files recursively

I have a very long and complex string in many files and I want to remove/replace it recursively. The string contains many slashes, backslashes and spaces and any kind of special signs. How do I do ...
5
votes
3answers
204 views

Replace multiple strings in a single pass

I'm looking for a way to replace placeholder strings in a template file with concrete values, with common Unix tools (bash, sed, awk, maybe perl). It is important that the replacement is done in a ...
0
votes
1answer
151 views

Search for pattern across multiple files and replace a sub-part in all occurences

I am helping a friend with her thesis written in LaTeX and I need a quick solution for a "search and replace". Using a terminal in Linux, how can I find the following pattern: \caption{*\cite{*}} ...
3
votes
3answers
83 views

How to do more than one substring replace at once in bash?

I have a directory contains image files that are to be echoed in bash. While echoing, I want to replace both file name and extension in single line command. Example files: images/file_name_1.jpg ...
0
votes
1answer
303 views

Copy file while replacing text in it

I'm writing a script to publish a webapp. While copying files, I must replace a placeholder current_date in a file with the current date. I would start with something like this to define the date ...
5
votes
4answers
485 views

sed how to substitute when string has “http://” in it?

I have a file xx that has the following contents: @base_url = "http://dmstaffing-stage.herokuapp.com/" I want to use sed to eliminate this line (replace with nothing). I have used this sed ...
2
votes
3answers
1k views

Substitute placeholders in template

Say I have a shell configuration file config like this: HOST=localhost PORT=8080 Now I have a template template like this: The host is <%= @HOST %> The port is <%= @PORT %> How do I ...
2
votes
3answers
793 views

Collapse repeating characters

Is there a more Bashist way than echo "$PWD//" | sed -e 's#//\+#/#g' to replace repeating slashes with a single one? Thanks Steven D, now there's a fully working function to find the longest common ...