Reputation
2,373
Top tag
Next privilege 2,500 Rep.
Create tag synonyms
Badges
6 23 59
Impact
~458k people reached

May
29
awarded  Notable Question
May
26
awarded  Nice Answer
May
25
comment 14.04 - Laptop Battery Indicator does not show the right battery percentage
Did my answer help you? Could you please either give me a comment on my answer or accept it?
May
25
reviewed Reject I can't find my launcher
May
23
revised How to find manually installed packages?
Change quotes, write something about Ansible
May
9
accepted Upgrade to Kubuntu 15.04 broke settings and Akonadi
May
5
comment Access individual lines of a text file and create separate text file with that name
Could you please choose one of the answers as your accepted one?
May
4
comment Access individual lines of a text file and create separate text file with that name
The read() reads all the lines into memory. What one could improve is to use for item, content in zip(open(…), open(…)): since that only reads the lines as needed. This will then work with arbitrary file sizes since it only uses generator expressions.
May
4
comment Access individual lines of a text file and create separate text file with that name
Although I fear that you will end up with \n at the end of the files. Now that I think about it, either your filenames have \n in them, or you files lack \n at the end of the lines. This is not a problem since there is only one line in it, but I prefer my files to end with \n, so that cat *.txt gives reasonable output.
May
4
comment Access individual lines of a text file and create separate text file with that name
Sure, it will be taken care of. It's not like the computer would break because it ran out of file descriptors. I just like it a habit to not write any code that leaks anything . Your last version looks pretty golfed, but you could make it even shorter by using open(…).readlines(), see this Stack Overflow question ;-).
May
4
comment Access individual lines of a text file and create separate text file with that name
That does work with spaces in the files :-).
May
4
comment Access individual lines of a text file and create separate text file with that name
You could just use done < "$1" in the last line, no need to introduce another variable. The all capital letter variables are usually only used for environment variables (like PATH or EDITOR). When you write a shell script, you can just use lowercase variable names, like you did with count.
May
4
revised Access individual lines of a text file and create separate text file with that name
Format the advantages
May
4
comment Access individual lines of a text file and create separate text file with that name
Using null (\0) as a field delimiter be a bit less arbitrary, programs like find -print0 use this as a delimiter, and xargs -0 can read those. Since \0 is illegal for names in the filesystem, I think, this is fine for filenames. In a text file, you can have \0, I think, so that might break. Also you replace \n with your symbol. Couldn't you use that as a delimiter in awk directly? And if you have a file with DOS or Mac OS line breaks (\n\r and \r), it will not work. Your filenames are now just numbered instead of using the words in the second file. Did I miss something?
May
3
comment Access individual lines of a text file and create separate text file with that name
Given the way the question was posed, I do not see awareness for the troubles that spaces might bring when implementing this with shell scripts. Therefore I assume that the OP just gave a minimal example which does not contain spaces for simplicity, not because he/she is sure that there never will be spaces. I got burned with software not coping with spaces often enough myself, so I try my best to make new software cope with spaces well.
May
3
revised Access individual lines of a text file and create separate text file with that name
Advertise argparse advantages
May
3
comment Access individual lines of a text file and create separate text file with that name
I think that will break with spaces in the words as well.
May
3
comment Access individual lines of a text file and create separate text file with that name
The problem with those kind of solutions is that somebody will come along with a file that does contain spaces and then it breaks in a non-obvious way. That is what I do not want to have in my software.
May
2
comment Access individual lines of a text file and create separate text file with that name
You can use for item, content in zip(lines(sys.argv[1]), lines(sys.argv[2])) and have this even shorter. It won't matter in a short script like this, but that would leak file descriptors when you use open () without a context manager (with open() as f:).
May
1
revised Access individual lines of a text file and create separate text file with that name
Add spaces