fork download
  1. #!/bin/bash
  2. regex='^(_[^_]*_)[^_]*(_.*\.txt)$'
  3. myvar='bar'
  4. result=$(sed -E "s/$regex/\1$myvar\2/")
  5.  
  6. echo $result # echo _12345_bar_678.txt
Success #stdin #stdout 0.01s 5528KB
stdin
_12345_23_678.txt
stdout
_12345_bar_678.txt