[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [PROGRAMMERING] Vælg tilfældig fil i Bash



Anders Misfeldt wrote:
Hej,
Hvordan kan man i bash udvælge en tilfældig fil i en mappe? Filerne hedder ikke noget med 1, 2, 3 eller noget. De har alm. navne :-)
Hvordan kan man det?
så vælger scriptet en af filerne tilfældigt.

Med gode gamle Sed og Awk kan man faktisk det meste.


    find -type f -maxdepth 1 | \
      gawk '{a[FNR-1]=$0;} END { srand();  printf("%s\n", a[int(rand()*(1.0*FNR))])}' | \
      sed  -e 's/^.\///'

Virker ogsaa med mellemrum i filer og andre spoejse tegn.
Virker ogsaa med ingen filer.

Men det er jo lidt snyd. Det er jo ingen ren bash-loesning ;')

--PMM



 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 22:43 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *