Skip to main content
added 53 characters in body
Source Link
terdon
  • 252.7k
  • 69
  • 481
  • 719

There are two issues here. First, your sed command is in single quotes (''), so the variable isn't expanded:

$ echo $ruledeck /praj/test/drc_tsn/test1 $ echo '$ruledeck' $ruledeck 

I see you've put the variable in double quotes within the sed command, but that won't change anything since the entire thing is single quoted. You need to double quote it instead:

sed -e "3s/$/$ruledeck/" file 

However, that will also break:

$ sed -e "3s/$/$ruledeck/" file sed: -e expression #1, char 8: unknown option to `s' 

This is because your variable contains /, but you are also using / as the delimiter for the substitution operator (s///). You need a different delimiter. This should do what you want:

$ sed -e "3s|$|$ruledeck|" file #############Actions################# set a [project $p get_action ICV_DRC] action $a set_parameter "ruledeck"/praj/test/drc_tsn/test1 action $a set_parameter "options" 

But that still isn't quite right if the line doesn't have a space in the end. To also add the space, but only if it isn't there already, use \? ( a space and an escaped question mark) to match "0 or 1 space". Putting all this together gives:

$ sed -e "3s| \?$| $ruledeck|" file #############Actions################# set a [project $p get_action ICV_DRC] action $a set_parameter "ruledeck" /praj/test/drc_tsn/test1 action $a set_parameter "options" 

There are two issues here. First, your sed command is in single quotes (''), so the variable isn't expanded:

$ echo '$ruledeck' $ruledeck 

I see you've put the variable in double quotes within the sed command, but that won't change anything since the entire thing is single quoted. You need to double quote it instead:

sed -e "3s/$/$ruledeck/" file 

However, that will also break:

$ sed -e "3s/$/$ruledeck/" file sed: -e expression #1, char 8: unknown option to `s' 

This is because your variable contains /, but you are also using / as the delimiter for the substitution operator (s///). You need a different delimiter. This should do what you want:

$ sed -e "3s|$|$ruledeck|" file #############Actions################# set a [project $p get_action ICV_DRC] action $a set_parameter "ruledeck"/praj/test/drc_tsn/test1 action $a set_parameter "options" 

But that still isn't quite right if the line doesn't have a space in the end. To also add the space, but only if it isn't there already, use \? ( a space and an escaped question mark) to match "0 or 1 space". Putting all this together gives:

$ sed -e "3s| \?$| $ruledeck|" file #############Actions################# set a [project $p get_action ICV_DRC] action $a set_parameter "ruledeck" /praj/test/drc_tsn/test1 action $a set_parameter "options" 

There are two issues here. First, your sed command is in single quotes (''), so the variable isn't expanded:

$ echo $ruledeck /praj/test/drc_tsn/test1 $ echo '$ruledeck' $ruledeck 

I see you've put the variable in double quotes within the sed command, but that won't change anything since the entire thing is single quoted. You need to double quote it instead:

sed -e "3s/$/$ruledeck/" file 

However, that will also break:

$ sed -e "3s/$/$ruledeck/" file sed: -e expression #1, char 8: unknown option to `s' 

This is because your variable contains /, but you are also using / as the delimiter for the substitution operator (s///). You need a different delimiter. This should do what you want:

$ sed -e "3s|$|$ruledeck|" file #############Actions################# set a [project $p get_action ICV_DRC] action $a set_parameter "ruledeck"/praj/test/drc_tsn/test1 action $a set_parameter "options" 

But that still isn't quite right if the line doesn't have a space in the end. To also add the space, but only if it isn't there already, use \? ( a space and an escaped question mark) to match "0 or 1 space". Putting all this together gives:

$ sed -e "3s| \?$| $ruledeck|" file #############Actions################# set a [project $p get_action ICV_DRC] action $a set_parameter "ruledeck" /praj/test/drc_tsn/test1 action $a set_parameter "options" 
added 487 characters in body
Source Link
terdon
  • 252.7k
  • 69
  • 481
  • 719

There are two issues here. First, your sed command is in single quotes (''), so the variable isn't expanded:

$ echo '$ruledeck' $ruledeck 

I see you've put the variable in double quotes within the sed command, but that won't change anything since the entire thing is single quoted. You need to double quote it instead:

sed -e "3s/$/$ruledeck/" file 

However, that will also break:

$ sed -e "3s/$/$ruledeck/" file sed: -e expression #1, char 8: unknown option to `s' 

This is because your variable contains /, but you are also using / as the delimiter for the substitution operator (s///). You need a different delimiter. This should do what you want:

$ sed -e "3s|$|$ruledeck|" file #############Actions################# set a [project $p get_action ICV_DRC] action $a set_parameter "ruledeck"/praj/test/drc_tsn/test1 action $a set_parameter "options" 

But that still isn't quite right if the line doesn't have a space in the end. To also add the space, but only if it isn't there already, use \? ( a space and an escaped question mark) to match "0 or 1 space". Putting all this together gives:

$ sed -e "3s| \?$| $ruledeck|" file #############Actions################# set a [project $p get_action ICV_DRC] action $a set_parameter "ruledeck" /praj/test/drc_tsn/test1 action $a set_parameter "options" 

There are two issues here. First, your sed command is in single quotes (''), so the variable isn't expanded:

$ echo '$ruledeck' $ruledeck 

I see you've put the variable in double quotes within the sed command, but that won't change anything since the entire thing is single quoted. You need to double quote it instead:

sed -e "3s/$/$ruledeck/" file 

However, that will also break:

$ sed -e "3s/$/$ruledeck/" file sed: -e expression #1, char 8: unknown option to `s' 

This is because your variable contains /, but you are also using / as the delimiter for the substitution operator (s///). You need a different delimiter. This should do what you want:

$ sed -e "3s|$|$ruledeck|" file #############Actions################# set a [project $p get_action ICV_DRC] action $a set_parameter "ruledeck"/praj/test/drc_tsn/test1 action $a set_parameter "options" 

There are two issues here. First, your sed command is in single quotes (''), so the variable isn't expanded:

$ echo '$ruledeck' $ruledeck 

I see you've put the variable in double quotes within the sed command, but that won't change anything since the entire thing is single quoted. You need to double quote it instead:

sed -e "3s/$/$ruledeck/" file 

However, that will also break:

$ sed -e "3s/$/$ruledeck/" file sed: -e expression #1, char 8: unknown option to `s' 

This is because your variable contains /, but you are also using / as the delimiter for the substitution operator (s///). You need a different delimiter. This should do what you want:

$ sed -e "3s|$|$ruledeck|" file #############Actions################# set a [project $p get_action ICV_DRC] action $a set_parameter "ruledeck"/praj/test/drc_tsn/test1 action $a set_parameter "options" 

But that still isn't quite right if the line doesn't have a space in the end. To also add the space, but only if it isn't there already, use \? ( a space and an escaped question mark) to match "0 or 1 space". Putting all this together gives:

$ sed -e "3s| \?$| $ruledeck|" file #############Actions################# set a [project $p get_action ICV_DRC] action $a set_parameter "ruledeck" /praj/test/drc_tsn/test1 action $a set_parameter "options" 
Source Link
terdon
  • 252.7k
  • 69
  • 481
  • 719

There are two issues here. First, your sed command is in single quotes (''), so the variable isn't expanded:

$ echo '$ruledeck' $ruledeck 

I see you've put the variable in double quotes within the sed command, but that won't change anything since the entire thing is single quoted. You need to double quote it instead:

sed -e "3s/$/$ruledeck/" file 

However, that will also break:

$ sed -e "3s/$/$ruledeck/" file sed: -e expression #1, char 8: unknown option to `s' 

This is because your variable contains /, but you are also using / as the delimiter for the substitution operator (s///). You need a different delimiter. This should do what you want:

$ sed -e "3s|$|$ruledeck|" file #############Actions################# set a [project $p get_action ICV_DRC] action $a set_parameter "ruledeck"/praj/test/drc_tsn/test1 action $a set_parameter "options"