[SOLVED] Substituting zeros with dots in 2nd and 3rd field of a text file.
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's 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.
Substituting zeros with dots in 2nd and 3rd field of a text file.
Say I have this data ped.rc with fields;
1 0 0
2 0 0
3 0 0
4 0 0
5 0 0
6 0 0
7 0 0
8 0 0
9 0 0
10 0 0
11 0 0
12 14 3
13 0 0
14 17 9
I am trying to replace the 2nd and 3rd fields that have only 0's with dots but leave others that are non zeros the way they are. Can anyone help me out. Thanks
Do both the second and third have to be zero for a replacement or is it replace a zero in those fields no matter if both or one?
Here is an alternative assuming not both:
Moderator note: please use a descriptive title for your thread excluding words like 'urgent', 'help' or 'hello'. Using a proper title makes it easier for members to help you. This thread has been reported for title modification. Please do not add replies that address the thread title.
Sorry to be a pain, but I don't understand your code (new to awk it's one of the languages which I'm trying to make efforts to learn). What does the '1' at the end do? Does it just tell awk to print the line out, or is it something deeper than that? I understand the a?b:c constructs you've got.
Got it in one Any expression not in braces is evaluated and if true the braces are entered, but if no braces then the default action is performed, which is print.
Got it in one Any expression not in braces is evaluated and if true the braces are entered, but if no braces then the default action is performed, which is print.
In addition it's worth to mention what is true and false in awk
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.