I have a file name like below, and I want to print the file name before .tar. How I can do this?
Note: the part after .tar is fixed but the part before .tar is variable.
Example: abcd_ef_1.2.3.12+all.tar.gz.md5sum
I have a file name like below, and I want to print the file name before .tar. How I can do this?
Note: the part after .tar is fixed but the part before .tar is variable.
Example: abcd_ef_1.2.3.12+all.tar.gz.md5sum
Using sed for example:
sed -E 's/(.*)\.tar.*/\1/' <<< "abcd_ef_1.2.3.12+all.tar.gz.md5sum"
prints abcd_ef_1.2.3.12+all.
$ basename -s .tar.gz.md5sum 'abcd_ef_1.2.3.12+all.tar.gz.md5sum'
abcd_ef_1.2.3.12+all
With Parameter Expansion
$ s='abcd_ef_1.2.3.12+all.tar.gz.md5sum'
$ echo "${s%.tar*}"
abcd_ef_1.2.3.12+all
combine find and sed maybe?
find . -maxdepth 1 -name "*.tar*" | sed 's/\(.*\)\(\.tar.*\)/\1/g'
explanation: the first part of sed
\(.*\)\(\.tar.*\)
find the tar, but provide 2 grouping. 1 before the .tar and 1 after the tar
the second part of sed
\1
take only the first grouping(before the .tar)