Questions tagged [sed]
sed is a command-line stream editor for filtering and transforming text.
7,399 questions
3
votes
6
answers
392
views
How can I use sed to chain append lines from a text file, add it as a suffix to the text on the same lines numbers on another file, and so on?
I've tried using sed for this. I've tried putting the lines of interest in variables as well.
I have two examples I want to achieve for now. Lets say I have thousands of urls in a file called links....
2
votes
1
answer
201
views
Replacing the domain string in the compiled binary file with an IP address
Just in theory: is it possible to replace the domain string in the compiled binary file with an IP address by editing a binary file in place with sed? (IP address belongs to a different domain, but ...
0
votes
2
answers
59
views
How to replace all `[` and `]` in sed?
Logical way would be to use an 's/[\[\]]/_/g' regexp replace, however it does not work as intended to.
It replaces a chain of [ and ] with a single _.
$ echo 'x[]x'|sed -E -e 's/[\[\]]/_/g'
x_x
$ echo ...
0
votes
2
answers
144
views
Process sed capture group with a bash function before replacement: "sh: 1: <bash function>: not found"
So, I was playing around with this answer, when I found that neither
printf_stdin () {
read input
printf "$input"
}
sed "/lorem ipsum foobar/ {
s/'/'\"'\"'/g
s/\...
0
votes
3
answers
68
views
Sed match string and copy it to another line (with added lines) in specific place
Need to find the first instance of a string in a yaml file and insert it alond with a couple new lines after a specific line. Trying to find the first instance of 'rtr-*' and copy it out with a ...
3
votes
2
answers
201
views
Syntax Error on ssed for Regex Subroutine definitions
I'm stuck with this error without clue or reference how to solve it:
I have this list on text.txt
Angie Apple
Angie Banana
Angie Tomato
Angie Peach
Angie Onion
I'm running substitution through ssed (...
-1
votes
1
answer
80
views
sed: why my regex does not work correctly
So, I'm facing a curious issue with sed; I have reduced my problem down to the following. Why does
sed -e 's/\"\([^\"]*\)\">/\1/' <<< '["\{">'
return ["\{&...
1
vote
3
answers
681
views
How does -e work in sed?
This is the content of input.txt:
foo-bar
foo-baz
I want to substitute - with _ and join the two lines.
Notice the difference between using -e and a pipe when using sed:
$ sed -e 's/-/_/g' -e ':a; N;...
1
vote
0
answers
61
views
Wrap long lines using GNU sed
The following expression is reasonably effective at wrapping long lines of text (for the purpose of dumping to my 128 characters wide terminal window and reading):
s~(.{104,124}) ~\1\n~g
This ...
2
votes
3
answers
377
views
sed: invalid usage of line address 0
I need to keep only last 30 days events in the log and remove other data.
Log has timestamp (date +%e/%b/%Y:%H:%M) and next line values like
01/Jan/2025:00:00
value1
value2
...
01/Jan/2025:06:45
...
7
votes
1
answer
386
views
ESC/escape character `\c[` in GNU sed substitution
The ESC character is 0x1B. In GNU sed, it can be used as 0x1b. It can also be used as \c[ ²; this, however, behaves inconsistently:
sed "s/XXX/\c[/" # right-hand side, no problem
sed &...
0
votes
5
answers
397
views
How to perform sed replacement from the rule file only on certain lines?
I have rules.txt file with sed rules for replacement.
s/1/a/
s/2/b/
s/3/c/
etc...
I want to replace characters only after certain line 5.
This command does not work.
sed -n '5,$p' -f rules.txt ...
3
votes
2
answers
186
views
Embedded special characters skewing sed output
The Issue
I've been parsing a file with sed trying to tweeze out the desired data. This has worked fine for most lines in the file but there appears to be some embedded special characters that are ...
-1
votes
7
answers
614
views
Insert a character after every 2 character but discard first 2 characters
I want to print a colon after every 2 characters of alphanumeric Value and I found something like below. But I am not sure how to remove initial 2 characters from the output and what is the meaning of ...
4
votes
4
answers
485
views
Remove new lines and everything after comment symbol with awk or sed
How to remove comments and newline symbols without using two pipes.
I have bookmarks.txt file with comments.
https://cookies.com # recipes cookbook
https://magicwands.com # shopping
I can copy link ...