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.
the '-i' parameter tells sed to edit the file in place. The 's' is the search/replace command, the $ means "match end of line", so '39$' is a match for 39 followed by a newline character. The second pair in // (/85/ in this case) is what to replace it with.
Cool, that seems easy enough. I have a couple of questions though.
What would I do if I only wanted to change the value of at the end row2: no matter what value it has? (ie. I don't need to find a specific number, i just need to update a value at the end of a row. Is there a way I can just go to that location and ovewrite whatever is there? Maybe using grep and gawk?
And with the command you just gave me, will I run into problems if there are multiple entries of the same number? Say if I wanted to change row2 from a 39 to 84 but row1 has a 39 as well.
1. Do you mean you want to make updates based on row number and not the contents of the row? That's a little uglier but certainly possible, using head, tail, and grep maybe.
2. The command I listed will change all occurances that match the pattern specified. If you only want to change certain lines you need a way to specify only those lines. Is there anything else in the line that uniquely identifies the ones you want to change?
Post a more complete description/example of what you're trying to do.
1. Yes I want to make editions based on a row number and not the content.
2. Yes, I only want to change a specific line. The only thing specific to the line is the label "row#:"
Basically I have a c program which will calculate a number. This number is to be writen to the text file. And there is a specific spot for this result. This document is then copied to other computers. So the other computers know the result of a certain operation. To extract a certain number I use the grep and gawk commands. I think this is the command:
grep row2: filename.txt | gawk '{print$2}'
This gets the line for row2: and gets whatever is in the second column.
Now I just need a way to write something to a specific spot in the text document.
I figure using Linux commands will be much easier than what would have to be done in the C program.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.