In some cases I like to use the awk interpreter for quick task. There are probably a more DSL/Groovy way to do these actions, but awk is so neat and clean.

Example 1

Lang: groovy
node{
  stage('EX1'){
    sh """#!/bin/bash
      echo "red green blue purple" | awk '{print \$3}'
    """
  }
}

output:

Lang:
[in_jenkins-dsl-test_hw_test-L6OPGZSILNYU4LFJKDMY4AGUBMSB2FT3Z3UAW66ODUIPZN4WUNBA] Running shell script
blue