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

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Comfirmed that this works, many thanks! Is there a similar way to get the date and time in the filename too?
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).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.