I have a really long port map where I want to replace a bunch of
SignalName[i],
with
.SignalName(SignalName[i]),
I think I can do this easily with regular expressions, but I can’t for the life of me figure out how. Any ideas?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Assuming SignalData is the file containing your port map information, the following would do what you want.
In sed s stands for substitution, regex between the first pair of // is used to match against each line. If a match is found the expression between upto the next / is made to replace what was matched.
Explanation of regex
Finally we use these captured strings to construct the desired string.
If you want to experiment with this before running on your file use sed -s instead of sed -si. That will show the results of the transformation on stdout, without actually changing the file