Cut the first field and the 2 last field

Hello,

I would like to cut the first field and the 2 last fields from the string.Please help.
Here is the example of the string.

DL_FUND_FULL_20190605.txt
DL_FUND_HIS_DEL_20190605.txt
DL_FUND_HIS_TMP_DEL20190605.txt

Please noted that
DL_ --> Every files have the prefix like this.
FULL_YYYYMMDD,DEL_YYYYMMDD --> There are 2 types of the suffix files like this.
The rest in the centre is Table names which cannot define how many character they have
FUND,FUND_HIS,FUND_HIS_TMP

I would like to get the name of table thus I use this command

echo "DSL_EDUCATE_LEVEL_FULL_20190605.ctl" | rev | cut -d "_" -f3- | rev

The answer for each line are:

DL_FUND
DL_FUND_HIS
DL_FUND_HIS_TMP

However, I cannot figure out how to cut DL_ into that command. The result that I would like to have are

FUND
FUND_HIS
FUND_HIS_TMP

Welcome to the forum.

Why not extend the logics that you already apply, like

rev | cut | rev | cut -d"_" -f2-

? But, this would require to create and run four processes per table name. Better to use shell builtins like

while read FN; do FN="${FN#*_}"; echo "${FN%_*_*}"; done < file
FUND
FUND_HIS
FUND_HIS
EDUCATE_LEVEL

, or, use a short sed script:

sed 's/^[^_]*_//; s/\(_[^_]*\)\{2\}$//'  file
2 Likes

Thanks a lot!

$ awk -F"DL_|_(DEL|FULL)_[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]" ' { print $2 } ' file
FUND
FUND_HIS
FUND_HIS_TMP