How to split a string using Awk

Using Awk a string may be split at least using two different methods.

Let’s split the strings given in file foo. The file consists of 5 columns separated by a comma (,) so we will split the lines at “,”.

awk ‘{split($0,array,”,”)}{print array[1],array[2],array[3],array[4],array[5]} foo

awk -F “,” ‘{print $1,$2,$3,$4,$5}’ foo

Where foo is a file such as this e.g:
1005.709115,-3.974680,0.081765,3.265020,Wed 23 Nov 2011 11:27:14 AM UTC
1006.709004,-3.974761,0.084558,3.265004,Wed 23 Nov 2011 11:27:15 AM UTC
1007.708987,-3.973002,0.087218,3.265001,Wed 23 Nov 2011 11:27:16 AM UTC
1008.709055,-3.969182,0.089719,3.265034,Wed 23 Nov 2011 11:27:17 AM UTC


Superconduting gravimeter at Svalbard observes M9.0 earthquake

Friday 11 March 2011 at 0546UT a big M9.0 earthquake happened approximately 200 km outside Sendai, Japan.
The earthquake was observed with a Superconducting gravimeter located in Ny-Ålesund, Svalbard approximately 10 minutes later.
This figure shows what the superconducting gravimeter observed.


Norske postnummer

En liste over Norske postnummer med koordinater er tilgjengelig fra Erik Bolstads webside.



Soldiagram benyttes for å visualisere hvordan skyggene kastes fra feks bygninger. Dette er aktuelt ved nybygg og påbygning.
Jeg kan beregne soldiagram og hvordan Solen beveger seg over himmelen sett fra et gitt ståsted feks Oslo.

Kontakt ove at azimuth dot biz for mer informasjon.
Tlf: 90523434


Visiting Reykjavik

Geodesy at work in Reykjavik, Iceland

My visit to Reykjavik, this time – mid September 2010, was work related.
My original working plan was to make a gravity tie and then demobilize a sea gravimeter.
Prior to my arrival, my contact person at Iceland had informed me that there would possible be a strike by the ship engineers starting sometime after they have arrived in the harbor. However, there was no information when the strike would begin.

After arriving at Keflavik airport, I took a taxi to the Reykjavik harbor to pick up the land gravimeter and do the gravity tie before the boat arrived. However, the boat was already there.
So the measurements of the gravity tie was postponed and I started demobilizing the sea gravimeter hoping to be finished before the strike would begin.
Working as fast as possible, after less than one hour, I was ready to put the instrument into the wooden travel boxes and bring then off the ship.

Then, the strike started!

So, instead, I did the gravity tie, connecting the measurements made by the sea gravimeter to land measurements.

Gravity tie at the harbour


Find minimum and maximum using AWK

Let’s assume you want to find the minimum and/or maximum of a column of numbers in a given file using AWK.

Assume we have an input file foo with f.ex. line number in first column and in the second ($2) and third column ($3 in awk) we have the values of interest.

File: foo

1 2 40
2 3 23
3 15 -12
4 8 -1
5 11 0

Use the following awk commando find minimum and maximum of the columns of interest:

awk ‘NR == 1 {max=$2 ; min=$2} $2 >= max {max = $2} $2 <= min {min = $2} END { print "Min: "min,"Max: "max }' foo


awk ‘BEGIN{ max = -999999999 ; min = 9999999999 } $2 > max {max = $2} $2 < min {min = $2} END{ print "Min: ",min, "Max: ",max }' foo

The result will be for column 2:

Min: 2 Max: 15

and for column 3:

Min: -12 Max: 40

Standard deviation

Here you may see how to calculate the standard deviation using AWK.

Average or arithmetic mean

Here you may see how to calculate the average or arithmetic mean using AWK.


Protected: Markus i huska og overnatter hos Beste

This post is password protected. To view it please enter your password below:


Protected: Vaffelkake

This post is password protected. To view it please enter your password below:


Harstad og sommersolverv

Jeg fikk et lite oppdrag her om dagen.
Rundt sommersolverv skal noen gjøre filmopptak i Harstad.
I den forbindelse var det ønsket å finne når Solen står i nord og sør for 21. og 22. juni 2010. Altså for dagene rundt sommersolverv.

Harstad kirke Nord Sør
21.06.2010 00:55 12:55
22.06.2010 00:56 12:56

Sommersolverv inntreffer 13:28 (norsk sommertid!) den 21. juni 2010. Dette gjelder for hele verden!

Ønsker du å få beregnet Solens posisjon, eller hvordan skyggen beveger seg over tomten din pga naboens nybygg?
Da kan jeg beregne dette for deg!

Ta kontakt på: ove at azimuth dot biz
Eller legg igjen en beskjed i kommentarfeltet.


Pythons Simple HTTP Server

There is a nice little feature in Python that a friend of mine showed me. You may use Python as a Web Server… and that is right out of the box. No additional programs to install or any tweaking at all :-)

Move to the folder you want to make available for others to see.
Then type
python -m SimpleHTTPServer

If you want to use a special port you may type something like this:

python -m SimpleHTTPServer 8713

Others may browse your directory and directories below.
If you haven’t specified a port, in your browser type :

Or, if you have specified a port

Enjoy :-)

Older posts «