Workout #22: Reading and Writing CSV
Oct 8, 2021
The new file’s contents are the username (index 0) and the user ID (index 2). Note that a record may contain a comment, in which case it will not have anything at index 2; you should take that into consideration when writing the file. The output file should use TAB characters to separate the elements.
Thus, the input will look like this:
root:*:0:0::0:0:System Administrator:/var/root:/bin/sh
daemon:*:1:1::0:0:System Services:/var/root:/usr/bin/false
# I am a comment line
_ftp:*:98:-2::0:0:FTP Daemon:/var/empty:/usr/bin/false
and the output will look like this:
root 0
daemon 1
_ftp 98
TRY IT YOURSELF
ANSWER
https://colab.research.google.com/drive/1Y1SdxKBCG5GiYSKyowqZWJliSKy8RS-j?usp=sharing