Tagged Questions
5
votes
2answers
55 views
How to report “sed” in-place changes
When using sed to replace strings in-place, is there a way to make it report the changes it does (without relying on a diff of old and new files)?
For instance, how can I change the command line
...
7
votes
2answers
132 views
How could I use Bash to find 2 bytes in a binary file, increase their values, and replace?
I'm trying to find two bytes inside binary file, then increase value of those two bytes and replace them inside file. Those two bytes are on positions 0x82-0x83. For now on I have successfully ...
5
votes
3answers
154 views
How to insert text after the last configuration line?
I have to insert a line into a configuration files automatically, but with the added caveat that it should be inserted before a multi-line footer comment and any preceding empty or whitespace-only ...
2
votes
2answers
1k views
How can I replace text after a specific word using sed?
I have a file named .ignore. In need to replace the projdir. For example:
ignore \..*
ignore README
projdir Snake
I need to replace Snake with, for example, "PacMan". I read the man page, but I ...
2
votes
3answers
498 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 ...
1
vote
4answers
395 views
Replace text between brackets
I'm using awk '{ gsub(/BAR|WIBBLE/, "FOO"); print }' to replace text in data like:
SOMETHING [BAR, WIBBLE]
SOMETHING [BAR]
This gives the desired result of:
SOMETHING [FOO, FOO]
SOMETHING [FOO]
...
6
votes
2answers
374 views
shell script/utility replace 2 byte unicode in binary file
I have many large Unicode files. I would like to replace each Unicode byte pair with a new Unicode byte pair. For example, the original file contains
"C3 B9 C3 AB C3 B8 C3 B0"
and I would like to ...
4
votes
3answers
134 views
Smart way to perform a similar replacement (not simple enough for diff) in multiple files?
I have a bunch of files (45, so too many to edit them manually without going crazy) which all require the same changes (as seen in the three diffs at the end of this question).
Most tools used for ...
2
votes
2answers
174 views
Add info under specific line
I want to know how could I add files contain information under specific line in file.
For example, I have file1.txt with the following lines:
line 1
line 2
line 3
and file2.txt has the ...
3
votes
1answer
2k views
How to do multiline search and replace text (delete) recursively
I want to go recursively through a directory and search for specific content in all files. The content should then be replaced if found. With a single line I would make something like this:
find . ...
2
votes
2answers
300 views
remove only specific text occurrences from string using sed
I have a text file that contains many rows of this sort of thing:
/*[17:51:27][1 ms]*/ UPDATE `country` SET `region_id` = '4' WHERE `country_id` = '36';
Is there a way that I can use sed to remove ...
2
votes
1answer
256 views
Duplicate selected words with sed and replace it
I have to modify a document containing xml data; one modification I couldn't set up with sed.
I have to modify the following expressions from:
<Bild ...
1
vote
2answers
205 views
How to split vCards lines
Related to How to join vCards lines, vCard does a weird kind of line splitting: If a line contains more than 75 characters, insert a "CR, LF, space" sequence. Thus the following line:
...
2
votes
1answer
240 views
How to join vCards lines
vCard uses a special way to split long lines: At 75 characters, insert a DOS newline and a space. Joining therefore means to replace all occurrences of the sequence "CR, LF, space" with an empty ...
3
votes
2answers
1k views
use awk to replace parentheses?
How can I use awk to replace the parentheses in these 2 scenarios?
Change empty parens to the word "None"
192.168.0.24,Up,()
Remove parens to only host.domain.com is left
...