ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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.
In the former I want to replace the first occurrence only of "<", ">", or "." with "_". Any occurrence of these symbols after a space need to be left as is.
The second example shows that sometimes there is no occurrence of the symbols prior to a space. In those cases the line is left completely unchanged.
If I were using awk with the default delimiter I would only do a substitutions on the first field. Sounds simple but I don't know how to substitute in awk, I always use sed. However, in sed I have no idea how to substitute characters only when they occur before a space.
Your wording is a little vague. Do you mean you want to replace all instances of all three [<>.] characters, but only in the first field? Or you only want to replace the first instance of each character in the line, as long as it's in the first field? Or only the first instance of any of the three? Or what?
I'm going to assume the first, in which case simply use awk's gsub function.
Also, please use [code][/code] tags around your code, to preserve formatting and to improve readability. Do not use quote tags, as they don't preserve whitespace.
Your wording is a little vague. Do you mean you want to replace all instances of all three [<>.] characters, but only in the first field? Or you only want to replace the first instance of each character in the line, as long as it's in the first field? Or only the first instance of any of the three? Or what?
I'm going to assume the first, in which case simply use awk's gsub function.
Also, please use [code][/code] tags around your code, to preserve formatting and to improve readability. Do not use quote tags, as they don't preserve whitespace.
Your assumption was correct. I'll try this in the morning when I get to work.
Your wording is a little vague. Do you mean you want to replace all instances of all three [<>.] characters, but only in the first field? Or you only want to replace the first instance of each character in the line, as long as it's in the first field? Or only the first instance of any of the three? Or what?
I'm going to assume the first, in which case simply use awk's gsub function.
Also, please use [code][/code] tags around your code, to preserve formatting and to improve readability. Do not use quote tags, as they don't preserve whitespace.
This was almost perfect. The only problem was that it does exactly what I said I wanted. Unfortunately there were a few cases where I did not want a "." changed. CDL has keywords that alway have a leading ".", e.g. .ENDS, .SUBCKT, and .INCLUDE but it's easy enough to pipe the awk command to sed and restore the keywords.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.