fork download
  1. #!/bin/bash
  2.  
  3. # ideone boilerplate: run in temp dir
  4. t=$(mktemp -d -t ideone.XXXXXXXX) || exit
  5. trap 'rm -rf "$t"' ERR EXIT
  6. cd "$t"
  7.  
  8. cat <<\: >input.csv
  9. COLUMN 1,COLUMN 2
  10. 3-Entrepreneurship,"innovation, daily"
  11. ,countless
  12. 2-Police/Enforcement,"innocent, protect"
  13. 2-Bathroom:home room,toilet handle
  14. 3-Companies,née dresses
  15. 2-Sense of Smell,odorless
  16. 3-Entrepreneurship,old ideas
  17. 3-Entrepreneurship,¡new income streams!
  18. 3-Companies,Zoë’s food store
  19. ,many
  20. 2-Police/Enforcement,crime
  21. 2-Bathroom:home room,bath room
  22. ,ring
  23. 3-Companies,móvíl résumés
  24. 2-Sense of Smell,musty smell
  25. 3-Entrepreneurship,good publicity guru!
  26. 3-Companies,Señor
  27. :
  28.  
  29. cat <<\: >prog.py
  30. #!/usr/bin/env python3
  31.  
  32. import csv
  33. from pathlib import Path
  34.  
  35. with open('input.csv') as csvin:
  36. # skip header
  37. reader = csv.reader(csvin)
  38. reader.__next__()
  39. for row in reader:
  40. if row[0]:
  41. if '/' in row[0]:
  42. Path(row[0]).parent.mkdir(parents=True, exist_ok=True)
  43. with open(row[0] + '.txt', 'a+') as txtout:
  44. txtout.write(row[1] + '\n')
  45. :
  46.  
  47. python3 prog.py
  48.  
  49. tail *.txt */*.txt
Success #stdin #stdout 0.05s 11956KB
stdin
Standard input is empty
stdout
==> 2-Bathroom:home room.txt <==
toilet handle
bath room

==> 2-Sense of Smell.txt <==
odorless
musty smell

==> 3-Companies.txt <==
née dresses
Zoë’s food store
móvíl résumés
Señor

==> 3-Entrepreneurship.txt <==
innovation, daily
old ideas
¡new income streams!
good publicity guru!

==> 2-Police/Enforcement.txt <==
innocent, protect
crime