.. _playing_sed_running: How to run :command:`sed` ? --------------------------- There are two ways of running :command:`sed`: - you can give the commands on the command line:: sed 's/yes/done/' file If you want to use several commands, you have to use the ``-e`` option:: sed -e 's/yes/done/' -e 's/no/not-done/' file - it is also possible to place the commands in a seperate file:: sed -f sedsrc file where :file:`sedsrc` contains the necessary commands. | | .. _sed_exercises: ******** **Exercises** ******** #. On our parallel machines, the nodes where the command can run are listed in the file :file:`/usr/spool/machines`. However the first node is mentioned 2 times. How can we remove the first line of this file, so that each node is mentioned one time ? How can we count how many nodes we have in this parallel environment ? (Use the command :command:`wc`) An example file is at ``/data/tccm/linux_bash/5/machines`` .. Solution cat /usr/spool/machines | sed 1d cat /usr/spool/machines | sed 1d | wc -l #. How can we use :file:`machines` from previous exercises to duplicate each node, so to make a machines file where each node is mentioned two times ? .. Solution cat /usr/spool/machines | sed -e 1d -e p #. How should you make a general gaussian-inputfile, where the number of processors is not specified but filled in on run-time ? - to get the number of cores available, see in the file :file:`/proc/cpuinfo` and use :command:`grep` and :command:`wc` [#store]_ - to specify the number of procs in a gaussian-inputfile, you have to add a line like:: %nprocshared=8 How can you make this general so that the number is always correct for the node where the job is running ? ******** .. [#store] You can store the output of a command in a variable by including the command in $(...), (see :ref:`this section `) For example biggest_file=$(ls -lSr | tail -1) ..