Skip to content

01.Simple arithmetic *

Task 1

List the files in your home folder: ls -l
The output should look something like this:

$ ls -l 
total 88608
drwxr-sr-x 6 user uu_mkem 2048     Dec 17 2007 acml4.0.1 
drwxr-sr-x 7 user uu_mkem 10240    Jan 21 2014 bin 
drwxr-sr-x 2 user uu_mkem 2048     Mar 19 2010 bin64 
drwxr-sr-x 9 user uu_mkem 2048     Oct 18 2007 castep 
drwxrwsr-x 2 user uu_mkem 2048     Jan 18 2013 ddt 
drwxr-sr-x 2 user uu_mkem 2048     Dec 20 2006 _del 
drwxr-sr-x 2 user uu_mkem 2048     Mar 26 2013 Desktop 
-rw-r--r-- 1 user uu_mkem 319954   Aug 15 2012 dftbp_1.2_src.tar.gz 
drwxr-sr-x 2 user uu_mkem 2048     Mar 26 2013 Documents 
drwxr-sr-x 2 user uu_mkem 2048     Mar 26 2013 Downloads 
-rw-r----- 1 user uu_mkem 20730896 Aug 8  2011 espresso-4.3.2-examples.tar.gz 
-rw-r----- 1 user uu_mkem 15116712 Aug 8  2011 espresso-4.3.2.tar.gz 
-rw-r----- 1 user uu_mkem 8101479  Jul 5  2011 etc.tgz
  1. Write a one-line awk script to calculate the occupied space (5th column) in this folder. ( * )
  2. Modify the script to count only the files in your home directory (hopefully you have some in your home folder) (hint: directories begin with ā€dā€ in the access field) ( * )

Task 2

The table below contains coordinates of atomic positions in Angstrom.
Copy/paste the text in a file coord.dat on your computer.

coord.dat

0.8997508593245822  0.2048785172349154  0.0717195259190714
0.9490486395984686  0.9146565172390164  0.7689034265935394
0.8752470144992109  0.8523867265774260  0.8626469653565847
0.8640857283636117  0.9207732244914749  0.1291593060111536
0.9392794897450530  0.7856183128719006  0.1151153726165936
0.3493798807138794  0.1485424348042750  0.4300844752418486
0.3877406330134096  0.1931874740146635  0.5746869696493597
0.4376693404820234  0.9063674424632875  0.2740320628086707
  1. Write a one-line awk script to add 1 to each number in the second column. ( * )
  2. Modify the script to multiply all numbers by factor of 1.8897 . ( * )
Possible solutions

Task 1.

1) ls -l | awk '       {s=s+$5} END {print s}'
2) ls ā€“l | awk ' !/^d/ {s=s+$5} END {print s}'

Task 2.

1) awk '{print $1,$2+1.,$3}' coord.dat
   or 
   awk '{$2=$2+1; print}' coord.dat
2) awk 'BEGIN{a2b=1.8897261}  {print $1*a2b,$2*a2b,$3*a2b}' coord.dat