Sorting Files in Different
Directories
I've got several files in different directories like
this:
aa/t1
aa/bb/t2
aa/t2
aa/bb/cc/t1
aa/t3
and would like to get this sorting:
aa/t1
aa/bb/cc/t1
aa/t2
aa/bb/t2
aa/t3
Which means, sorting all files considering the last
number in the name of the file.
Code:
find ... |
perl -le'
print sort {
($aa) = $a
=~ /(\d+)$/;
($bb) = $b
=~ /(\d+)$/;
$aa <=>
$bb
} <>
'
Please provide a small script for the following senario:
step1: need to find some files in a directory for ex
having 020909
step2: sort them and redirecting to new file
(ex:sort abc > abc.sort)
I am trying this but giveing flag error
ls -l *.020909* |grep -v .sort| while read file
do
sort "$file" > "$file".sort
done
In your original script "ls -l" (ell) should have been
"ls -1" (one) to just get the filename.
Here's a version with some minor tweaks. It starts with
ls hyphen one.
ls -1 *\.020909* 2>/dev/null | grep -v "\.sort$" | while
read file1
do
file2="${file1}.sort"
echo "Sorting ${file1} into ${file2}"
sort < "${file1}" > "${file2}"
done
Have a Unix Problem
Unix
Forum - Do you have a UNIX Question?
Unix Books :-
UNIX Programming,
Certification, System Administration, Performance Tuning Reference Books
Return to : - Unix
System Administration Hints and Tips
(c) www.gotothings.com All material on this site is Copyright.
Every effort is made to ensure the content integrity.
Information used on this site is at your own risk.
All product names are trademarks of their respective
companies.
The site www.gotothings.com is in no way affiliated with
or endorsed by any company listed at this site.
Any unauthorised copying or mirroring is prohibited.
|