You are not logged in.

#1 2010-12-27 08:53:34

stryder
Member
Registered: 2009-02-28
Posts: 500

[solved] bash script find help

I have a lot of text files (song lyrics) that I want to put into 1 file and I created a bash script to do it, thus:

find . -name "*.txt" | while read file; do
echo -e "\n\n$file\n\n" >> ../emcsongs1a.txt
cat "$file" >> ../emcsongs1a.txt
done
exit 0

The problem is that the songs are not appended in alphabetical order. How can I achieve this? Have googled around but no help so far.

Sample results:

./in_the_image_of_god.txt
./in_the_presence_of_your_people.txt
./into_thy_presence_lord.txt
./it_is_no_secret.txt
./a_clare_benediction.txt
./a_merry_heart.txt
./a_new_commandment.txt
./a_thousand_candles.txt

Actually starts with "e" and then later went to "a" then jumps to "g" and so on. Not sure what the order is here.

Last edited by stryder (2010-12-27 09:01:42)

Offline

#2 2010-12-27 08:56:11

Allan
Pacman
From: Brisbane, AU
Registered: 2007-06-09
Posts: 11,487
Website

Re: [solved] bash script find help

sort them tongue

find . -name "*.txt" | sort | while read file; do

Offline

#3 2010-12-27 09:00:29

stryder
Member
Registered: 2009-02-28
Posts: 500

Re: [solved] bash script find help

hmmm, looks like a simple:

find . -name "*.txt" | sort | while read file; do

does the trick. Just didn't think...

Thanks Allan.

Last edited by stryder (2010-12-27 09:02:30)

Offline

Board footer

Powered by FluxBB