SED

  • The sed command performs string substitutions.
  • It is usually used to add, remove or change parts of a string.
  • This is often invaluable for modifying variables.

  • Syntax for changing STRING1 to STRING2 is:
      sed s/STRING1/STRING2/g

  • Example:
    $ v="im*.nii.gz"
    $ v=`echo $v | sed s/im/Subject/g`
    $ echo $v
      Subject1.nii.gz Subject2.nii.gz Subject3.nii.gz

  • Warning: The characters . * [ ] / have special meaning in the first string unless preceded by a backslash
  • Tip: Any character can be used instead of /
    e.g.   sed s@STRING1@STRING2@g
    which can be very handy when dealing with directories/files