I came across this code sed '\,^@, s/ABC/XYZ/' filename What does \,^@, means here. I thought comma , operator defines the line range on which substitute expression will operate.

  • \, means , is regex delimiter instead of usual /... ^@ to match @ at beginning of line... , to end the match... s/ABC/XYZ/ to perform substitutions only on lines matching @ at beginning of line...
    – Sundeep
    Apr 11 '18 at 13:26
  • Thanks Sundeep, sorry but I am still not clear. I understood ^@ denotes lines starting with @. Are you saying \, means alternate regex delimeter , then shouldn't it be just ,@, or \,@\,. Thanks Apr 11 '18 at 13:46
  • @CppLearner for substitute commands, s,foo,baz, will work.. but for address matching, you need extra \ at start...
    – Sundeep
    Apr 11 '18 at 14:30

According to the man page, In a context address, the construction "\cBREc", where c is any character other than backslash or newline, shall be identical to "/BRE/". So your script is identical to

sed '/^@/ s/ABC/XYZ/' filename

which means the replacement is only to be done in lines starting with @

  • Perfect Philippos. This is what I was looking for thanks a lot for your help and explanation. Upvoting and accepting this as answer. Thank you. Apr 11 '18 at 15:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.