First off: I don't have a real problem I need to get fixed. And I know my way around on Linux fairly well.
Now: It's not a problem with 'cut' per se. The value I need is actually in the 4th column but since there are two spaces at the begining of ea. line i have to take -f6. No problems here and that's not what was puzzling me!
The thing where my script goes wrong is the redirection after the cut operation. Writing to the same file which was used in the 'tail' doesn't work. Add some arbitrary extension to $file (like you suggested and I already posted) and everything works fine.
I was just wondering where the problem is exactly.
Considering the following flow of command execution:
- tail opens the file, operates on it, closes it (in that order? I don't know)
- the pipe runs the stdout to cut (does this create a subshell???)
- cut takes some column (which contains data and is not empty)
- output redirection to file fails and the resulting files are empty.
BUT: Sometimes (about every 100 times) it does what is expected and the file only contains field 6!
I also tried to debug that line by investigating the output of every command involved. There is no problem except when the last output is redirected to the file.
Again: I don't need help in getting the script to work! Thanks for trying though!
Edit: Ok I tried s.th. here: Instead of redirecting the output to a file with > I did it with 'tee'. After the tee the output is sent to /dev/null. Result: No erronous behaviour as above. Shell script is faster by 2.5 secs (corresponds to 30% in my case). Nice!