Tutorial Bash 03

download Tutorial Bash 03

of 2

Transcript of Tutorial Bash 03

  • 7/22/2019 Tutorial Bash 03

    1/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 workon the last tutorials.

    Wanna Chocolate? (MCMCs)

    This (challenging!) task deals (indirectly) with cosmolo-gical parameter estimation. There, Markov Chain MonteCarlo simulations are used to sample the CMB likelihoodfor a given cosmological model.Seven chains have been run in parallel, lea-ding to the files montecarlo chain0.dat, . . . ,

    montecarlo chain6.dat. Each line of one of thefiles contains data for one point of the correspondingchain. The last column is the multiplicity of that point.As soon as the chains have converged, the last columncontains the entry 0 (which can occur only once per

    file).The aim is to obtain all points after convergence in onefile with filename distilled.dat, i.e., all lines of the 7files starting with the line after the one containing the0 each.This is a typical task which can be solved quickly (if youknow how) using some bash tools in a short and elegantway. The challenge for you is to write a shell script orcommand that is as short as possible to solve this task.It has to be run in the directory MCMC/without alteringany of the files that are already in it, creating the file

    distilled.dat in the same folder. Make sure that youdont hand over any parameters to your script.

    Send your solution today until 14:30 to [email protected] or hand it in in some other formin the tutorial. The winner (the first one sending in the shortest solution countingall characters including whitespaces) gets one bar of chocolate on Thursday.

  • 7/22/2019 Tutorial Bash 03

    2/2

    2

    Practising Bash Tools

    This part is easier and to practise some of the bash tools.

    1. Get the file story.tgzfrom the courses website. You could use wget for this task.

    2. Uncompress the contents, and change to the directory story.

    3. List all text files recursively in this directory, its subfolders, subsubfolders, ...

    4. Change the text Bilbo to Frodo in all text files.

    5. How often do the wordsGandalf and morning appear each?

    6. Compute the total number of lines of all text files.

    7. Gather the complete text in a new file story.txt in the main folder. To this end, youneed to access the.txtfiles in the correctly numbered order, i.e. 0 , 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, . . .Check whether your new file has the same number of lines than you found out in theprevious question.

    8. Capitalize the first letter ofeach word.

    9. Delete all words and.