I have several (vhdl) files containing a pattern with newline characters that I need to replace by another pattern that also contains newline characters.
I start with something like:
Code:
port (
A : in std_logic_vector(width - 1 downto 0);
Z : out std_logic;
);
I want to replace it by something like:
Code:
port (
A : in std_logic_vector(width - 1 downto 0);
B : in std_logig;
Z : out std_logic;
);
(I need to paste some lines)
As I need to do this (very) often I want to use a shell script.
I tried:
1.
Code:
#!/bin/sh
sed -i 's/ A : in std_logic_vector(width - 1 downto 0);
Z : out std_logic;/ A : in std_logic_vector(width - 1 downto 0);
B : in std_logig;
Z : out std_logic;/g' ./testfile
result:
Code:
sed: -e expression #1, char 5: unterminated `s' command
2.
Code:
#!/bin/sh
sed -i 's/ A : in std_logic_vector(width - 1 downto 0);\n Z : out std_logic;/ A : in std_logic_vector(width - 1 downto 0);\n B : in std_logig;\n Z : out std_logic;/g' ./testfile
result:
File remains unchanged
3.
Code:
#!/bin/sh
awk '{sub(/ A : in std_logic_vector(width - 1 downto 0);
Z : out std_logic;/," A : in std_logic_vector(width - 1 downto 0);
B : in std_logig;
Z : out std_logic;")}1' ./testfile
result:
Code:
unexpected newline or end of string
4.
Code:
#!/bin/sh
awk '{sub(/ A : in std_logic_vector(width - 1 downto 0);\n Z : out std_logic;/," A : in std_logic_vector(width - 1 downto 0);\n B : in std_logig;\n Z : out std_logic;")}1' ./testfile
result:
Displays the unchanged testfile
Are there any suggestions how I can automate the pattern replacement?
Code:
$ sed --version
GNU sed version 4.1.5