Questions tagged [sed]
sed is a command-line stream editor for filtering and transforming text.
7,400 questions
-4 votes
5 answers
126 views
Linux: how to remove starting from chars?
I have those lines mycommand --option1 mycommand --option2 mycommand --option3 mycommand --option4 mycommand -h mycommand -i mycommand -z mycommand -1 I want to remove all until - or -- appear so I ...
3 votes
6 answers
433 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
222 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
86 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
163 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
4 answers
92 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
214 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
92 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
703 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
73 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
398 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
393 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
417 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
203 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
650 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 ...