36 questions
- Bountied 0
- Unanswered
- Frequent
- Score
- Trending
- Week
- Month
- Unanswered (my tags)
0
votes
1
answer
96
views
Sed's append command (a) is for some reason deleting all file's text and then appending the provided text
I'm trying with GNU sed command to append a line into a file inside a block/section, specifically just a line under the start of the block/section. As a result it empties the file (maybe leaves a ...
0
votes
0
answers
67
views
Behavior of backslash in 'a' command in GNU sed
I don't understand the behavior of the backslash in the a command in gnu sed.
The version of gnu sed used is 4.9.
$ gsed --version
gsed (GNU sed) 4.9
Copyright (C) 2022 Free Software Foundation, Inc.
...
-1
votes
1
answer
48
views
How does backreferencing in the search pattern work in GNU Sed?
Given that
echo -e 'one.onetwo' | sed -n 's/\(.*\)\.1円/x/p'
prints xtwo, why does the following print onextwo?
echo -e 'one.two' | sed -n 's/\(.*\)\.1円/x/p'
1
vote
3
answers
135
views
sed if pattern match copy pattern line along with n number of lines after this to another file
I am looking for a sed command to match pattern and copy pattern line and n number of lines after this line.
pattern is 01, 02, 03 sequence.
Example:
group-title=01- line1
http://www.yahoo.com
group-...
1
vote
1
answer
97
views
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_ ...
1
vote
1
answer
1k
views
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
6
votes
1
answer
4k
views
Explanation of difference between GNU sed and BSD sed
I wrote the following command
echo -en 'uno\ndue\n' | sed -E 's/^.*(uno|$)/1円/'
expecting the following output
uno
This is indeed the case with my GNU Sed 4.8.
However, I've verified that BSD Sed ...
3
votes
2
answers
170
views
Regex for whitespace delimiter except for [ and ] characters
I consider my self pretty good with regular expressions, but this one is appearing to be surprisingly tricky.
I want to trim all whitespace, except the ones between "" and [] characters.
I ...
1
vote
1
answer
203
views
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 ...
-1
votes
1
answer
186
views
How to delete duplicate lines from a block using sed [duplicate]
Suppose we have a block of lines as given example below:
<segment1>
<element="1" prop="blah"/>
<element="2" prop="blah"/>
.
.
&...
2
votes
2
answers
87
views
GNU sed 4.2.1 matching second occurence
With this command I am trying to insert M09 between two patterns of M502 and the second line since M502 that looks like X41.5Y251.5T201.
Specifically I am trying to insert M09 before the last line.
...
0
votes
1
answer
460
views
-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 ...
0
votes
2
answers
167
views
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, ...
2
votes
1
answer
225
views
Replace First Occurrence Only of Pipe Character in String
I need to remove an extra pipe character at the end of header row of a pipe delimited csv file with sed. The literal string that I am trying to find is COLNAME|
Working on a GCP Windows server. The ...
2
votes
3
answers
131
views
Re-index two digit strings based on occurrence of a common string
I have a urlwatch .yaml file that has this format:
name: 01_urlwatch update released
url: "https://github.com/thp/urlwatch/releases"
filter:
- xpath:
path: '(//div[contains(@class,&...