0

I need some help with the following problem. I just can't figure it out (and yes I did the googlework etc).

Using csh I need to read one line from a file (there is only 1 line in the file), split it into separate strings (!not every value is separated with a space, however they do have a fixed position (always in the 3rd and 4th field)) and assign two of them to two separate variables in long format (so no E+04). The two values of interest are:

82390.43500000000 
 and
4.167000000000000
 (so without the 'Earth' attached to it).

They need to be assigned to respectively time and time_step.

The inputfile temp.txt looks like:

000520000001  260026 8.239043500000000E+04 4.167000000000000E+00Earth Centred Rotating                                          -9.999999999999998E+03-9999999.9999999-9999999.9999999-9999999.9999999

There are multiple files called temp.txt, however placed in different folders. The only part that stays constant in all files is Earth Centred Rotating.

What is the best way to do this (awk/grep/sed/?)?

Thanks!

skelter15
  • 3
  • 2
  • But... if you think of your `temp.txt` files, will the 2 values always be in the same "position" in the file? Given you example, I would call the values being in the 3rd and 4th Fields, or could it 5th and 9th in another file? (Please update your question with information and don't respond as a comment ;-) Good luck. – shellter Apr 07 '13 at 13:49
  • The first rule of C shell programming is "Don't"! – Jonathan Leffler Apr 07 '13 at 15:05
  • Solved it using bash instead of (t)csh :-) – skelter15 Apr 07 '13 at 17:10

1 Answers1

1
awk '{sub(/E.*/,"",$3); print$3}' temp.txt

and

awk '{sub(/E.*/,"",$4); print$4}' temp.txt

gives 82390.43500000000 and 4.167000000000000 respectively which can then be assigned to your variables.

Sidharth C. Nadhan
  • 2,191
  • 2
  • 17
  • 16
  • Thanks. For some reason it returns an empty line. And when I try to assign it: set var = `awk '{sub(/E.*/,"",$3); print$3}' temp.txt` and echo $var >> log.txt it returns ^^^_^T. – skelter15 Apr 07 '13 at 15:27