ipo ipo - 1 year ago 77
Linux Question

Output of wc -l without file-extension

I've got the following line:

wc -l ./*.txt | sort -rn

i want to cut the file extension. So with this code i've got the output:
number filename.txt

for all my .txt-files in the .-directory. But I want the output without the file-extension, like this:
number filename

I tried a pipe with cut for different kinds of parameter, but all i got was to cut the whole filename with this command.

wc -l ./*.txt | sort -rn | cut -f 1 -d '.'

Answer Source

Assuming you don't have newlines in your filename you can use sed to strip out ending .txt:

wc -l ./*.txt | sort -rn | sed 's/\.txt$//'