Vous êtes sur la page 1sur 2

Tobias Neckel

Max-Planck, October 2013

Bash course - Tutorial 3


Today, we only suggest some short tasks. This gives you the possibility to continue to work on the last tutorials.

Wanna Chocolate? (MCMCs)


This (challenging!) task deals (indirectly) with cosmological parameter estimation. There, Markov Chain Monte Carlo simulations are used to sample the CMB likelihood for a given cosmological model. Seven chains have been run in parallel, leading to the les montecarlo chain0.dat, . . . , montecarlo chain6.dat. Each line of one of the les contains data for one point of the corresponding chain. The last column is the multiplicity of that point. As soon as the chains have converged, the last column contains the entry 0 (which can occur only once per le). The aim is to obtain all points after convergence in one le with lename distilled.dat, i.e., all lines of the 7 les starting with the line after the one containing the 0 each. This is a typical task which can be solved quickly (if you know how) using some bash tools in a short and elegant way. The challenge for you is to write a shell script or command that is as short as possible to solve this task. It has to be run in the directory MCMC/ without altering any of the les that are already in it, creating the le distilled.dat in the same folder. Make sure that you dont hand over any parameters to your script. Send your solution today until 14:30 to neckel@in.tum.de or hand it in in some other form in the tutorial. The winner (the rst one sending in the shortest solution counting all characters including whitespaces) gets one bar of chocolate on Thursday.

Practising Bash Tools


This part is easier and to practise some of the bash tools. 1. Get the le story.tgz from the courses website. You could use wget for this task. 2. Uncompress the contents, and change to the directory story. 3. List all text les recursively in this directory, its subfolders, subsubfolders, ... 4. Change the text Bilbo to Frodo in all text les. 5. How often do the words Gandalf and morning appear each? 6. Compute the total number of lines of all text les. 7. Gather the complete text in a new le story.txt in the main folder. To this end, you need to access the .txt les in the correctly numbered order, i.e. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, . . . Check whether your new le has the same number of lines than you found out in the previous question. 8. Capitalize the rst letter of each word. 9. Delete all words and.

Vous aimerez peut-être aussi