Skip to main content

Questions tagged [sed]

sed is a command-line stream editor for filtering and transforming text.

-1 votes
1 answer
36 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 ["\{&...
Grass's user avatar
  • 101
1 vote
3 answers
607 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;...
glacier's user avatar
  • 489
1 vote
0 answers
36 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 ...
Lumi's user avatar
  • 864
2 votes
3 answers
332 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 ...
Aleksey's user avatar
  • 75
7 votes
1 answer
357 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 &...
Lumi's user avatar
  • 864
0 votes
5 answers
379 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 ...
normal_max's user avatar
3 votes
2 answers
172 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 ...
Gandalf's user avatar
  • 33
-1 votes
7 answers
528 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 ...
user984993's user avatar
4 votes
4 answers
450 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 ...
normal_max's user avatar
-2 votes
1 answer
139 views

sed inplace in selective block

I have a dir containing logstash config files these files have filter blocks, and sometimes nested child blocks need to match whole filter block filter { any text till final matching closing brace for ...
Sollosa's user avatar
  • 2,009
-4 votes
5 answers
226 views

Perl or sed script to remove a specific content of a file from another bigger file

I have a file (FILE1) with some repeated sections as below (example): LINE 1 ABCD LINE 2 EFGA LINE 3 HCJK REMOVE LINE11 REMOVE LINE12 REMOVE LINE13 LINE 4 ABCDH LINE 5 EFGAG LINE 6 HCJKD REMOVE ...
Pratap's user avatar
  • 45
-1 votes
3 answers
99 views

How to remove markdown links from headers with sed?

I'm trying to use sed to remove links like and leave just the title: ## [Some title](#some-title) This is my command: sed 's/^\(\#*\) *\[\([^\]]*\)\].*/\1 \2/' I expect to have just the text without ...
jcubic's user avatar
  • 10.4k
1 vote
6 answers
678 views

Change a double quote into a single quote with gnu sed when the quotes come before and after a parenthesis?

I'm using Debian 12 bookworm, gnu sed. I have this "Hello1" "('41-Z', 5001, 'A6')" "'Hello2'" "('42-Z', 5002, 'A7')" 'Hello3' "('43-Z', 5003, 'A8')" ...
shrykullgod's user avatar
1 vote
2 answers
124 views

How to extract a sub-heading as string which is above a search for word

I'm new to Bash and I've been self-taught. I think I'm learning well, but I do have staggering gaps in my base knowledge. So sorry if this is woefully simple bbuuuttt... Essentially, I need to sift ...
TC575's user avatar
  • 13
1 vote
3 answers
356 views

How to delete lines with sed if they contain a phrase?

I tried this sed -i '/^already satisfied$/d' loggocd.txt but lines like this one Requirement already satisfied: cryptography in /home/go/.pyenv/versions/3.9.1/lib/python3.9/site-packages are not ...
MJoao's user avatar
  • 47

15 30 50 per page
1
2 3 4 5
493