I have a filename following this model: 1.raw_bank_details_211.trg 2.raw_bank_details_222.trgI need to use the cut command in unix and cut the above string to obtain 211  and 222 from the strings and echo the value.I already used grep grep -o -E '[0-9]+', I need an alternative to this.
Extracting number from filename
shell;filenames;string;cut
cut is the wrong tool for that. To manipulate short strings such as file names, use the shell's string manipulation facilities whenever possible. All sh-type shells (sh, dash, bash, ksh, zsh, ) have some basic string manipulation as part of variable substitution. See e.g. the dash manual under parameter expansion. You can remove the shortest/longest prefix/suffix that matches a pattern.You want the last sequence of digits in the file name, so:Determine the non-numeric suffix by stripping everything up to the last digit.Remove that suffix.Strip everything up to the last non-digit.filename=1.raw_bank_details_211.trgsuffix=${filename##*[0-9]}number=${filename%$suffix}number=${number##*[!-0-9]}  Except some pre-POSIX Bourne shells, but you don't care about those.  