Advice for a fairly simple(?) script
Hi everyone,
I have bunch of files of this format Title number1,number2 10000 12000 L 0.7 0.7 0.0 I want to write a shell script that writes for each file: Temperature: number1 Time: 2nd_line * 6th_line Cooling Rate: (number1-number2)/(6th_line*4th_line) What's the most efficient way to go about this? I am not so bad with bash untill I have to batch process bunch of files like this. I know tiny little bit of awk and sed. Should I use them? Would it be an overkill if I do? Would expr utility be helpfull here? Please help. |
Code:
IFS=' |
Quote:
Alternative in Python: Code:
#!/usr/bin/python |
Another way in bash:
Code:
#!/bin/bash - |
OK thank you guys. Wow. I can't believe I lost all afternoon on this thing.
SOrry ghostdog, but I don't have time to deal with yet another language. Although from what you wrote python seems really powerfull. Jonaskoelker, thanks for the script. It didn't work out of the box, since shell doesn't do arithmetics with real numbers, so I had to pipe to bc. Also the second use of IFS (IFS=',') doesn't really do what it's supposed to and I don't really know how to fix that. Edit: Pete, thanks, I will see if your script works better. By the way, isn't it overkill to use awk and sed? I mean sed loads about 50K of memory and awk probably even more. Just curious. |
Quote:
##EDIT This seems to work with just sed: Code:
#!/bin/bash - |
Quote:
Quote:
|
Thanks guys, I spend half a day on this but it wasn't wasted - I learned tons. If someone sees this and has few minutes, I wouldn't mind a version with awk only.
Also, I was curious why switching IFS doesn't work in the first version. |
Hi.
Here's the beginning of an awk version, untested because there was no live data posted that I saw. You may need to adjust the variables, and, of course, remove the "next" statement ... cheers, makyo Code:
#!/bin/sh Code:
% ./a1 |
All times are GMT -5. The time now is 08:04 AM. |