Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Please can anyone explain to me in brief the syntax of this command.

Explanation in terms of how actually this command is written significance of each and every character used. I know the output of this command but want to learn how it is working .

sed -i 's|\(LAYOUT PATH \).*|\1 "../GDS/'$1'.gds"|g' drcCustimize2  

Thanks in advance Yisha

share|improve this question
First you have looked at the man page for sed and realize that this will edit the file (i.e. change and replace it with the edited contents). – mdpc Aug 26 '14 at 6:06
  • sed: Call the sed command
  • -i: Pass sed the -i option: Modify the file in-place
  • 's|\(LAYOUT PATH \).*|\1 "../GDS/'$1'.gds"|g': The '...'$1'..' are used to make this whole part one single argument to the sed command
  • s|\(LAYOUT PATH \).*|\1 "../GDS/'$1'.gds"|g:
    • s|pattern|replacement|options: s is the substitute (or search and replace) command, the | characters are used to separate the parts of that command from each other
    • \(LAYOUT PATH \): Search for the literal string "LAYOUT PATH ", and capture it into a group; the content of this group can be put into the replacement string using \1
    • .*: Match everything until the end of the line
    • \1: Put the matched group 1 into the replacement text
    • "../GDS/: Put the literal string "../GDS/ into the replacement text
    • $1: Put the first argument to the shell-script into the replacement text
    • .gds": Put the literal string .gds" into the replacement
    • g: Do the replacement for every match on a line; without the g, only the first match is replaced
    • drcCustimize2: The file that sed should change
share|improve this answer
Thanks a lot Daniel for clear explanation Regards Madhvi – yisha Aug 26 '14 at 7:14
Strictly speaking 's|\(LAYOUT PATH \).*|\1 "../GDS/'$1'.gds"|g' doesn't necessarily make up one argument because $1 is not quoted so the split+glob operator applies here. 's|\(LAYOUT PATH \).*|\1 "../GDS/'"$1"'.gds"|g' would be correct. – Stéphane Chazelas Aug 26 '14 at 9:27
Also, the g is useless, as a pattern ending with .* cannot possibly match a line more than once. – G-Man Aug 26 '14 at 21:35

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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