Nov
23

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 “,”.
Split
awk ‘{split($0,array,”,”)}{print array[1],array[2],array[3],array[4],array[5]} foo
-F
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… Continue reading »

Oct
20

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… Continue reading »

Jun
01

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… Continue reading »

Feb
25

Calculate standard deviation using AWK

The standard deviation ? (sigma) is the square root of the average value of (X – ?)2.
In the case where X takes random values from a finite data set x1, x2, …, xN, with each value having the same probability, the standard deviation is
  where 
Assume we have an input file foo with f.ex. line number… Continue reading »

Oct
27

Hard Drive Crashes … foremost to the rescue

If your hard drive crashes … you may use foremost to retrieve your documents, photographs and so on.
Foremost is a linux tool for conducting forensic examinations. Although intended for law enforcement purposes, it may be useful to other members of the community. Foremost reads through a file, such as a dd image file or a… Continue reading »

Aug
11

SSH and RSYNC without password

Tried of typing your password every time you use ssh or rsync? If so, you should create a local ssh key for your computer and append your key to the remote computers you usually login to.
1. Generate your ssh key on your local computer:
local> ssh-keygen -t rsa
2. If prompted for file name… Continue reading »

May
05

How to create a MySQL database

Here we will show how to install and create a MySQL database. We will also create a MySQL user with access to our new MySQL database. We will GRANT our user all privileges on using the database.
Install mysql
Install mysql-server from your distro or using apt-get install mysql-server. During installation you a password for root is… Continue reading »

Mar
30

Calculate average using AWK

The average or arithmetic mean is given as

Assume we have an input file foo with f.ex. line number in first column and in the second column ($2 in awk) we have the values of interest.
File: foo
1 2
2 3
3 6
4 8
5 11
Use the following awk commando to calculate average or arithmetic mean
awk ‘{s+=$2} END{print “Sum: “s,… Continue reading »

Mar
30

Merge two files using AWK

We may use AWK to easily join two files. Assume we have input files foo and foo2
Content of foo
OSL 59.9 10.9
TRD 62.7 11.8
… and foo2
OSL 25 m
TRD 36 m
Join the two files with AWK commando
awk ‘NR==FNR{a[FNR]=$0;next} {print a[FNR],$2,$3}’ foo foo2
or
awk ‘{str=$2;str2=$3; getline < "foo";printf "%3s %3.1f %3.1f %2f %1s\n", $1,$2,$3,str,str2}' foo2 Output will be: OSL… Continue reading »