Jerid Francom bio photo

Jerid Francom

Associate Professor of Spanish and Linguistics
Romance Languages
Wake Forest University

Curriculum vitae

Email Twitter Github Stackoverflow Last.fm

I’ve recently switched from bash to fish for my shell in UNIX. In this Note-to-self I want to document copying a random sample of files that fit certain characteristics to another directory using fish. Specifically, I select 200 files from the ACTIV-ES corpus from years 2000-present and copy them to a new directory.

The files look like this:

...
es_Argentina_1996_Bromato-de-armonio_video-movie_Comedy_333189.run
es_Argentina_1996_Moebius_movie_Sci-Fi_117069.run
es_Argentina_1997_La-furia_movie_Action_202362.run
es_Argentina_1998_Diario-para-un-cuento_movie_Drama_177705.run
es_Argentina_1999_La-venganza_movie_Action_226587.run
es_Argentina_2000_Nueve-reinas_movie_Crime_247586.run
es_Argentina_2001_El-hijo-de-la-novia_movie_Comedy_292542.run
es_Argentina_2002_Angel_tv-movie_n_315769.run
es_Argentina_2002_Ciudad-de-María_movie_Documentary_317252.run
es_Argentina_2002_Mercano,-el-marciano_movie_Animation_283476.run
es_Argentina_2002_Tres-pájaros_movie_Adventure_341625.run
es_Argentina_2002_Valentín_movie_Comedy_296915.run
...

The commands that I used ended up being: find, grep, shuf, and cat in combination with cp. So here’s the command:

$ cp (find . -name "*" | grep 'es_.*2\d\d\d_' | shuf -n200 | cat) ~/Desktop/aes

The trick here is with the command shuf and cat. The shuf command will take a random sample of some size and return it. Unfortunately it will not return as a file, but rather a directory (or at least that is what the error says when run without cat.) By adding cat the selected files are returned within the () to the cp function.

es_Argentina_2000_Nueve-reinas_movie_Crime_247586.run
es_Argentina_2001_El-hijo-de-la-novia_movie_Comedy_292542.run
es_Argentina_2002_Angel_tv-movie_n_315769.run
es_Argentina_2002_Ciudad-de-María_movie_Documentary_317252.run
es_Argentina_2002_Mercano,-el-marciano_movie_Animation_283476.run
es_Argentina_2002_Tres-pájaros_movie_Adventure_341625.run
es_Argentina_2002_Valentín_movie_Comedy_296915.run
es_Argentina_2003_Ciudad-de-Dios_movie_Drama_350720.run
es_Argentina_2003_El-fondo-del-mar_movie_Drama_322298.run
es_Argentina_2003_El-polaquito_movie_Drama_283552.run
es_Argentina_2004_Buena-vida-(Delivery)_movie_Comedy_397355.run
es_Argentina_2004_Deuda_movie_Documentary_424041.run
...