Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
2 votes
0 answers
49 views

Does POSIX specify sed -E? [duplicate]

sed uses basic regular expressions (BRE) by default. Some implementations offer an option to switch to extended regular expressions instead. GNU sed introduced the -r option to do so in version 3.01 ...
Socowi's user avatar
  • 635
0 votes
3 answers
753 views

sed portability: extended regex vs. backslash

We can write the next command in two ways: # using extended regex $ echo foobar | sed -E 's/(foo)(bar)/\2\1/' barfoo And: # using backslashes $ echo foobar | sed 's/\(foo\)\(bar\)/\2\1/' barfoo ...
schrodingerscatcuriosity's user avatar
4 votes
2 answers
6k views

Is the use of sed's "a" command to prefix a line portable?

I noticed the following interesting behavior: $ printf '%s\n' line{1..2} | sed $'1a\\\nPREFIX' line1 PREFIXline2 $ Interestingly, this behavior is only possible for the last command in a Sed script,...
Wildcard's user avatar
  • 37k
3 votes
3 answers
769 views

Is it portable to indent the argument to sed's 'i\' command?

I was under the impression from the POSIX specs for sed that it is necessary to left-align the text on the line following the i\ command, unless you want leading whitespace in the output. A quick ...
Wildcard's user avatar
  • 37k
1 vote
0 answers
66 views

How can I easily deal with differences between BSD and GNU sed? [duplicate]

BSD and GNU sed have some small differences in what arguments they accept. I just learned that I have to use different command lines when using -i: sed -i '' # BSD sed -i # GNU I solved this with ...
daniel kullmann's user avatar
4 votes
3 answers
743 views

Frequency of words in non-English language text: how can I merge singular and plural forms etc.?

I'm sorting French language words in some text files according to frequency with a focus on insight rather than statistical significance. The challenge is about preserving accented characters and ...
user avatar
7 votes
2 answers
2k views

Does `sed` exist in all *nixes?

My application will be running on all versions of Unix-based OS, say, Linux, MacOS, HP-UX, Sun Solaris , OSX, etc. I'm using the following sed command in a common place to delete the string matched ...
user2172617's user avatar
2 votes
5 answers
12k views

In-place editing using sed on AIX

Is there any undocumented flag in AIX's sed implementation that allows for in-place editing in the same way as with e.g. GNU sed? The manual shows no flag for this operation, which is one of the most ...
danielbmeireles's user avatar
61 votes
7 answers
22k views

How can I achieve portability with sed -i (in-place editing)?

I'm writing shell scripts for my server, which is a shared hosting running FreeBSD. I also want to be able to test them locally, on my PC running Linux. Hence, I'm trying to write them in a portable ...
Red's user avatar
  • 1,462
8 votes
3 answers
7k views

How to share a GNU sed script between Linux and Mac OS X

I have a GNU sed script I use on Linux; it is installed at /bin/sed and it seems it contains GNUisms. I have collaborators using Mac OS X. They have installed (non-GNU) sed, located at /usr/bin/sed, ...
equaeghe's user avatar
  • 644