Let's break it down one step at a time.
-- This address matches every line that has a colon in it, not just the first.
If you don't supply an address, it defaults to every line of the input. If you supply two (add1,add2), then it matches every set of lines starting and ending with those addresses.
-- This substitution command, without modifers, replaces the first
3 on the line matched with a 4.
-- (only at the end of s///g) This modifies the substitution
command to replace all 3's on the line
with 4's. It's not file global, it's line global.
So the command 'sed /:/ s/3/4/g
' changes all 3's to 4's on lines that contain colons.
The first 'g
' on your line is where the error lies. 'g' is not a stand-alone command in sed
. It's only valid [in the above sense] in ed
, where it does mean "global", i.e. apply it to all lines. In sed
you simply don't supply any addresses, as I mentioned.
Edit: Correction... 'g
a valid command, but it doesn't mean global. In sed
, it copies values from the hold space back to the pattern space, and is generally used when creating multi-line commands. The grymoire tutorial goes into this stuff in more detail: