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.
Hmm, maybe I'm missing something obvious, but I think it's actually quite a good method (provided you create a unique filename with mktemp(1)). This is the same method used by sed -i actually:
Take for instance a counter stored in a file, and accessed constantly by a thousand plus users. If you rm and then move, then the file may not exist at the time that some other user makes a grab for it. Not that such a scenario is at play in this case. But even if the timing never works out to fail that condition, it is still posible for the timing to work out where two or more users perform the same update because they grabbed the same old data before performing an update. Which can be an issue when the counter is used to generate unique IDs. Lame example, but sort of my point. It's not always a simple single threaded, single user world these days.
Take for instance a counter stored in a file, and accessed constantly by a thousand plus users.
Okay, in that scenario temp+mv is not sufficient, but adding a rm in the middle just makes the bug harder to uncover. A solution for that would be flock(1) around temp+mv.
Take for instance a counter stored in a file, and accessed constantly by a thousand plus users. If you rm and then move, then the file may not exist at the time that some other user makes a grab for it. Not that such a scenario is at play in this case. But even if the timing never works out to fail that condition, it is still posible for the timing to work out where two or more users perform the same update because they grabbed the same old data before performing an update. Which can be an issue when the counter is used to generate unique IDs. Lame example, but sort of my point. It's not always a simple single threaded, single user world these days.
That calls for a shared memory segment instead.
And the use of semaphores to serialize access. It is not an application for file level locking, though you can do that to. Open the file read/write, then lock for exclusive access.
And no, don't use fopen. Use open - that way you don't get the conflict/race with the buffer usage.
so this to me is really goofy, but sometimes the values in the 3rd column of my data are positive and sometimes they're negative idk??? but doesn't really matter why, and the same is true for the 4th column, again idk.
so i need to have an "if" statement in the script for each of column. so no matter how the data is given to me, i need all the values in the 3rd column to always be negative and all the values in the 4th column to always be positive.
so how do i include an if statement in there. i tried....
It is not clear whether you want to print only the values matching your criteria, or if you want to modify all of the values so that they do meet the citeria: "i need all the values in the 3rd column to always be negative and all the values in the 4th column to always be positive."
used $48, which is the 48th field in the input. In Perl, when you split on whitespace, like Awk does by default, the fields are indexed starting at zero instead of one. That was the basis for my comment about distinguishing between the input columns and the output columns.
Bear in mind that for things like awk the delimiter is a space. So if your filenames contain spaces, and you're trying to grab the whole filename, that could prove difficult. With various other quirks with quotes and commas and other things depending on what thing(s) your messing with at any given moment.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.