5.6.3. How to run sed ?

There are two ways of running 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 sedsrc contains the necessary commands.




Exercises


  1. On our parallel machines, the nodes where the command can run are listed in the 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 wc)

    An example file is at /data/tccm/linux_bash/5/machines

  2. How can we use machines from previous exercises to duplicate each node, so to make a machines file where each node is mentioned two times ?

  3. 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 /proc/cpuinfo and use grep and wc 1

    • 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 ?


1

You can store the output of a command in a variable by including the command in $(…), (see this section) For example

biggest_file=$(ls -lSr | tail -1)