Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

The sed FAQ
Prev Home Next

6.7. Known incompatibilities between sed versions

6.7.1. Issuing commands from the command line

Most versions of sed permit multiple commands to issued on the command line, separated by a semicolon (;). Thus,

       sed 'G;G' file

should triple-space a file. However, for non-GNU sed, some commands require separate expressions on the command line. These include:

  • all labels (':a', ':more', etc.)
  • all branching instructions ('b', 't')
  • commands to read and write files ('r' and 'w')
  • any closing brace, '}'

If these commands are used, they must be the LAST commands of an expression. Subsequent commands must use another expression (another -e switch plus arguments). E.g.,

     sed  -e :a -e 's/^.\{1,77\}$/ &/;ta' -e 's/\( *\)\1/\1/' files

GNU sed, ssed, sed15 and sed16 all permit these commands to be followed by a semicolon, so the previous script can be written:

     sed  ':a;s/^.\{1,77\}$/ &/;ta;s/\( *\)\1/\1/' files

Versions differ in implementing the 'a' (append), 'c' (change), and 'i' (insert) commands:

      sed "/foo/i New text here"              # HHsed/sedmod/gsed-30280
      gsed -e "/foo/i\\" -e "New text here"   # GNU sed
      sed1 -e "/foo/i" -e "New text here"     # one version of sed
      sed2 "/foo/i\ New text here"            # another version
The sed FAQ
Prev Home Next

 
 
   Reprinted courtesy of Eric Pement. Also available at https://sed.sourceforge.net/sedfaq.html Design by Interspire