Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
cdfId->simInfo->test3 = '(nil
instParameters (m es ne plug tvolt tunique)
netlistProcedure new
)
I want to modify each file to add an extra term into the instParameters line BUT only on the lines preceded by cdfId->simInfo->test2
So that it looks like;
It is not clear to me if the line containing instParameters have to be immediately preceded by cdfId->simInfo->test2. I guess you mean it should be under the cdfId->simInfo->test2 section. In this case you can do something like this in awk:
Code:
/cdfId->simInfo->test2/ {
# while not encounter instParameters print line and get next line
while ( $1 != "instParameters" ) {
print
getline
}
# line found: add extraterm before closing parenthesis
print substr($0,1,index($0,")")-1),"extraterm)"
# go to next line
getline
}
# print any other line not under "cdfId->simInfo->test2" section
1
Ok. In that case we don't need the while loop, just check if the line below cdfId->simInfo->test2 starts with instParameters:
Code:
/cdfId->simInfo->test2/ {
# print this line and get the next one
print
getline
# if it contains instParameters add extraterm before closing parenthesis
if ( $1 == "instParameters" )
print substr($0,1,index($0,")")-1),"extraterm)"
else
print
# go to next line
getline
}
# print any other line not under "cdfId->simInfo->test2" section
1
To run the awk code, save it in a file (for example extraterm.awk) and run the following command
Code:
gawk -f extraterm.awk file
where file is the file to be processed. Unfortunately awk cannot edit the file in place, so you have to redirect the output to a temporary file and then overwrite the original one:
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.