fork download
  1. #!/bin/bash
  2. string='/my/directory/file1_AAA_123_k.txt
  3. /my/directory/file2_CCC.txt
  4. /my/directory/file2_KK_45.txt'
  5. sed -n 's~^.*/[^_/]*_\([^/]*\)\.[^./]*$~\1~p' <<< "$string"
  6. sed -nE 's~^.*/[^_/]*_([^/]*)\.[^./]*$~\1~p' <<< "$string"
Success #stdin #stdout 0.01s 5316KB
stdin
Standard input is empty
stdout
AAA_123_k
CCC
KK_45
AAA_123_k
CCC
KK_45