Search code examples
bashshellunixsedls

Bash: Listing all file with .addr_book without file extensions


I wish to list all files in current directory with the file extension ".addr_book" without the extension being visible.

I have used ls | sed -e 's/\..*$//' but this displays all files in current directory. Is there a way to have it so it only displays .addr_book files.

Thank you.


Solution

  • for file in *.addr_book; do
        echo "${file%.addr_book}" # removes the trailing '.addr_book' from $file
    done