Questions tagged [gnu-sed]

Use this tag for questions specific to the GNU version of the stream editor sed. Notice that questions should not be about general (interactive) usage of GNU sed, but programming using GNU sed. For sed questions not specific to GNU sed, use the "sed" tag.

GNU sed is the GNU version of sed, a "non-interactive command-line text editor". It features several extensions to POSIX sed such as support of extended regular expressions (ERE), in-place editing, and case modifiers for substitutions.

The current version is GNU sed 4.4, released on 2017-02-04.

Links of interest

33 questions
1
vote
1 answer

replace substrings between patterns with sed GnuWin32

I want to try to find between patterns substrings then replace it Source example text: bbllaahh pattern1 blaah _SUBSTRING_ blah blaah bbblah bbllaahh pattern1 blah blaah _SUBSTRING_ blahh _SUBSTRING_ blaah blahh blah pattern2 blllah blaaah blahh…
jcoder
  • 11
  • 2
1
vote
1 answer

Insert Line with SED Before Each Multiline Range

How can I insert a line before each multiline range block and indent the blocks in gnu sed on windows? The files contain many code blocks of various length starting and ending with ```. Answers to many similar questions using a single line pattern…
flywire
  • 1,155
  • 1
  • 14
  • 38
1
vote
5 answers

find and replace multiple lines of string using sed

I have an input file containing the following numbers -45.0005 -43.0022 -41.002 . . . I have a target txt file line:12 Angle=30 line:42 Angle=60 line:72 Angle=90 . . . Using sed I want to replace the first instance of Angle entry in the target…
pshah
  • 43
  • 6
1
vote
2 answers

Why won't the tab be inserted on the first added line?

I am trying to add multiple lines to a file, all with a leading a tab. The lines should be inserted on the first line after matching a string. Assume a file with only one line, called "my-file.txt" as follows: foo I have tried the following sed…
unique_ptr
  • 233
  • 3
  • 9
1
vote
1 answer

What does the range-operator in "sed" actually do, is it broken in GNU/busybox?

I wonder whether the GNU and BusyBox implementations of "sed" may be broken. My default sed implementation is the one from GNU. POSIX says: An editing command with two addresses shall select the inclusive range from the first pattern space that…
1
vote
2 answers

Which characters combined with ^ don't need to be escaped in sed?

I have checked that ^* and ^& match lines beginning by * and &, which I didn't since they are special characters. But ^[ doesn't work. Is this "standard" behavior? Is there any rationale behind this? sed version used was "GNU sed 4.4".
jinawee
  • 492
  • 5
  • 16
1
vote
1 answer

Replace one capture group with another with GNU sed (macOS) 4.4

I've looked around some other peripheral questions and haven't been able to find a solution to my problem, so I'm sorry if this is a duplicate to something I missed. Basically, I have the following GNU sed command: sed -E -imr 's/^(\w)+/(\w)+$/g'…
Ezra Goss
  • 124
  • 8
1
vote
2 answers

sed append text after N-th occurrence

I have a template of the following script and I need to insert the different PARAM value for each case. case $1 in 1) export PARAM= ;; 2) export PARAM= ;; 3) export PARAM= ;; esac I just found an example how to insert the…
hustas88
  • 307
  • 3
  • 15
1
vote
4 answers

GNU sed specify the end position when appending text

I want to do two things by sed when matching a pattern: Replace the pattern with a string Append another string after this line Such as the original content in a text file is: abc 123 edf I want to replace 123 to XXX and append YYY after the…
WKPlus
  • 6,955
  • 2
  • 35
  • 53
0
votes
1 answer

Comments in sed command file

Can I put comments (or something functionally equivalent) into a sed command file? subs.sed s/this/that/g # comment s/it/they/g $ sed -i -f subs.sed <(echo this it) that they
theonlygusti
  • 11,032
  • 11
  • 64
  • 119
0
votes
1 answer

-i without argument: is GNU sed --posix option bugged or BSD sed is not POSIX-compliant?

This is mostly a curiosity question that arose here. From the man page of GNU sed 4.8 I read --posix disable all GNU extensions. so I understand that if a code like the following works, it means that -i without argument is…
Enlico
  • 23,259
  • 6
  • 48
  • 102
0
votes
2 answers

How add to any `{` and `:` character in a file a newline

I want to copy a given text file (on macOS or Unix in general) to stdout where to any { and : character a newline is added. I tried sed “s/{/{\n/g” myfile.txt Just for the curly bracket character, but this doesn’t seem to work. Do I need to…
halloleo
  • 9,216
  • 13
  • 64
  • 122
0
votes
1 answer

Use sed for Mixed Case Tags

Trying to reformat tags in an xlm file with gnu sed v4.7 on win10 (shoot me). sed is in the path and run from the Command Prompt. Need to escape some windows command-line characters with ^. sourcefile BEGIN ... V7906 03/11…
flywire
  • 1,155
  • 1
  • 14
  • 38
0
votes
2 answers

GNU sed and newlines with multiple scripts

Suppose we start with this string: echo "1:apple:fruit.2:banana:fruit.3:cucumber:veggie.4:date:fruit.5:eggplant:veggie.">list.tmp and want to end up with this…
TeejMonster
  • 105
  • 8
0
votes
1 answer

Output file empty for Bash script that does "find" using GNU sed (gsed)

I have many files, each in a directory. My script should: Find a string in a file. Let's say the file is called "results" and the string is "average." Then append everything else on the string's line to another file called "allResults." After…
Ant
  • 753
  • 1
  • 9
  • 24