fork download
  1. #!/bin/bash
  2. s='This is the first sample line 1
  3. this is the second sample line
  4. another line
  5.  
  6. total lines: 3 tot'
  7.  
  8. # Extract a non-whitespace chunk after a certain pattern
  9. grep -oP '^total lines:\s*\K\S+' <<< "$s"
  10.  
  11. # Extract a number after a pattern
  12. grep -oP '^total lines:\s*\K\d+(?:\.\d+)?' <<< "$s"
Success #stdin #stdout 0.01s 5580KB
stdin
Standard input is empty
stdout
3
3