1

I'm using iPython notebook on a 16 core machine (so there are 15 "engines"). If I run this cell ...

%%px
%%bash
echo 'hi' > file1.txt

... then the result is one file called file1.txt that is written to disk 15 times. What I really want is to write to 15 different files, file1.txt through file15.txt.

I'm new to all this, so I imagine there's a simple solution!

Thanks,

Retsreg

retsreg
  • 13
  • 3

1 Answers1

1

The Bash special variable $$ is the PID of the shell, so you could do this:

echo hi > file$$.txt

That will write files like file3392.txt etc., where the number is the PID of each session. You can later rename the files if you need to.

John Zwinck
  • 239,568
  • 38
  • 324
  • 436
  • Comfirmed that this works, many thanks! Is there a similar way to get the date and time in the filename too? – retsreg Jan 20 '15 at 02:49
  • You can try `file$$_$(date +%F_%T).txt`. The `$()` evaluates its argument as a command and captures the output string, and you can use whatever format you want in the `date` command (I chose a standard one). – John Zwinck Jan 20 '15 at 02:59