Adam
Adam

Reputation: 109

How to find out the number of files types in a directory

So i am trying to write a script to search through a directory and find the number files with the same type. I tried this:

find $directory -type f | file -b $SAVEFILES | cut -c1-40 | sort -n | uniq -c | sort -nr |

but the number of how many times the the same type is there is before the type and look like this:

    168 ASCII TEXT

How do I access value of the number and store it and afterwards move it after the text like this:

ASCII TEXT: 168

Upvotes: 1

Views: 54

Answers (1)

Cyrus
Cyrus

Reputation: 88776

Append with GNU sed:

| sed 's/^ *\([0-9]\+\) \(.*\)/\2: \1/'

or

| sed -r 's/^ *([0-9]+) (.*)/\2: \1/'

Upvotes: 2

Related Questions