Skip to main content
added 19 characters in body
Source Link
Porcupine
  • 2.2k
  • 4
  • 26
  • 60

From SED: insert text after the last line? - Unix & Linux Stack Exchange, I learnt that $ if used outside the substitution in sed represents the end of file. This I have tried to use in the follwing to replace all occurences of abc occuring after # Start and till end of the file by 123

Code:

file=Data.txt
Initial="# Start";
Final='\$'
orig="abc";
new="123"; 
sed -i -r -e "\!${Initial}!,\!${Final}!{s!${orig}!${new}!g}" ${file} ;

Data.txt

# Start

abc
abc

$

abc
abc

Output:

# Start

123
123

$

abc
abc

Expected Output:

# Start

123
123

$

123
123

What am I missing? i.e. How to tell to sed that $ means end of the file?


Note: I am clear with the idea that I am escaping $, as I am using double quotes in the sed expression (for safer variable expansion). I hope this is correct. Can you comment on this?

From SED: insert text after the last line? - Unix & Linux Stack Exchange, I learnt that $ if used outside the substitution in sed represents the end of file. This I have tried to use in the follwing to replace all occurences of abc occuring after # Start and till end of the file by 123

Code:

file=Data.txt
Initial="# Start";
Final='\$'
orig="abc";
new="123"; 
sed -i -r -e "\!${Initial}!,\!${Final}!{s!${orig}!${new}!g}" ${file} ;

Data.txt

# Start

abc
abc

$

abc
abc

Output:

# Start

123
123

$

abc
abc

Expected Output:

# Start

123
123

$

123
123

What am I missing? i.e. How to tell to sed that $ means end of the file?


Note: I am clear with the idea that I am escaping $, as I am using double quotes in the sed expression (for safer variable expansion).

From SED: insert text after the last line? - Unix & Linux Stack Exchange, I learnt that $ if used outside the substitution in sed represents the end of file. This I have tried to use in the follwing to replace all occurences of abc occuring after # Start and till end of the file by 123

Code:

file=Data.txt
Initial="# Start";
Final='\$'
orig="abc";
new="123"; 
sed -i -r -e "\!${Initial}!,\!${Final}!{s!${orig}!${new}!g}" ${file} ;

Data.txt

# Start

abc
abc

$

abc
abc

Output:

# Start

123
123

$

abc
abc

Expected Output:

# Start

123
123

$

123
123

What am I missing? i.e. How to tell to sed that $ means end of the file?


Note: I am escaping $, as I am using double quotes in the sed expression (for safer variable expansion). I hope this is correct. Can you comment on this?

added 145 characters in body
Source Link
Porcupine
  • 2.2k
  • 4
  • 26
  • 60

From SED: insert text after the last line? - Unix & Linux Stack Exchange, I learnt that $ if used outside the substitution in sed represents the end of file. This I have tried to use in the follwing to replace all occurences of abc occuring after # Start and till end of the file by 123

Code:

file=Data.txt
Initial="# Start";
Final='\$'
orig="abc";
new="123"; 
sed -i -r -e "\!${Initial}!,\!${Final}!{s!${orig}!${new}!g}" ${file} ;

Data.txt

# Start

abc
abc

$

abc
abc

Output:

# Start

123
123

$

abc
abc

Expected Output:

# Start

123
123

$

123
123

What am I missing? i.e. How to tell to sed that $ means end of the file?


Note: I am clear with the idea that I am escaping $, as I am using double quotes in the sed expression (for safer variable expansion).

From SED: insert text after the last line? - Unix & Linux Stack Exchange, I learnt that $ if used outside the substitution in sed represents the end of file. This I have tried to use in the follwing to replace all occurences of abc occuring after # Start and till end of the file by 123

Code:

file=Data.txt
Initial="# Start";
Final='\$'
orig="abc";
new="123"; 
sed -i -r -e "\!${Initial}!,\!${Final}!{s!${orig}!${new}!g}" ${file} ;

Data.txt

# Start

abc
abc

$

abc
abc

Output:

# Start

123
123

$

abc
abc

Expected Output:

# Start

123
123

$

123
123

What am I missing? i.e. How to tell to sed that $ means end of the file?

From SED: insert text after the last line? - Unix & Linux Stack Exchange, I learnt that $ if used outside the substitution in sed represents the end of file. This I have tried to use in the follwing to replace all occurences of abc occuring after # Start and till end of the file by 123

Code:

file=Data.txt
Initial="# Start";
Final='\$'
orig="abc";
new="123"; 
sed -i -r -e "\!${Initial}!,\!${Final}!{s!${orig}!${new}!g}" ${file} ;

Data.txt

# Start

abc
abc

$

abc
abc

Output:

# Start

123
123

$

abc
abc

Expected Output:

# Start

123
123

$

123
123

What am I missing? i.e. How to tell to sed that $ means end of the file?


Note: I am clear with the idea that I am escaping $, as I am using double quotes in the sed expression (for safer variable expansion).

added 56 characters in body
Source Link
Porcupine
  • 2.2k
  • 4
  • 26
  • 60

From SED: insert text after the last line? - Unix & Linux Stack Exchange, I learnt that $ if used outside the substitution in sed represents the end of file. This I have tried to use in the follwing to replace all occurences of abc occuring after # Start and till end of the file by 123

Code:

file=Data.txt
Initial="# Start";
Final='\$'
orig="abc";
new="123"; 
sed -i -r -e "\!${Initial}!,\!${Final}!{s!${orig}!${new}!g}" ${file} ;

Data.txt

# Start

abc
abc

$

abc
abc

Output:

# Start

123
123

$

abc
abc

Expected Output:

# Start

123
123

$

123
123

What am I missing? i.e. How to tell to sed that $ means end of the file?

From SED: insert text after the last line? - Unix & Linux Stack Exchange, I learnt that $ if used outside the substitution in sed represents the end of file. This I have tried to use in the follwing to replace all occurences of abc occuring after # Start and till end of the file by 123

Code:

file=Data.txt
Initial="# Start";
Final='\$'
orig="abc";
new="123"; 
sed -i -r -e "\!${Initial}!,\!${Final}!{s!${orig}!${new}!g}" ${file} ;

Data.txt

# Start

abc
abc

$

abc
abc

Output:

# Start

123
123

$

abc
abc

Expected Output:

# Start

123
123

$

123
123

What am I missing?

From SED: insert text after the last line? - Unix & Linux Stack Exchange, I learnt that $ if used outside the substitution in sed represents the end of file. This I have tried to use in the follwing to replace all occurences of abc occuring after # Start and till end of the file by 123

Code:

file=Data.txt
Initial="# Start";
Final='\$'
orig="abc";
new="123"; 
sed -i -r -e "\!${Initial}!,\!${Final}!{s!${orig}!${new}!g}" ${file} ;

Data.txt

# Start

abc
abc

$

abc
abc

Output:

# Start

123
123

$

abc
abc

Expected Output:

# Start

123
123

$

123
123

What am I missing? i.e. How to tell to sed that $ means end of the file?

edited tags
Link
don_crissti
  • 85.6k
  • 31
  • 234
  • 262
Loading
Source Link
Porcupine
  • 2.2k
  • 4
  • 26
  • 60
Loading