File tree 2 files changed +43
-4
lines changed
2 files changed +43
-4
lines changed Original file line number Diff line number Diff line change @@ -24,3 +24,27 @@ Song title
24
24
"Adore You"
25
25
"Africa"
26
26
```
27
+
28
+ ### Step: 3
29
+
30
+ ```
31
+ $ cut -f"1 2 3" sample.tsv
32
+ f0 f1 f2
33
+ 0 1 2
34
+ 5 6 7
35
+ 10 11 12
36
+ 15 16 17
37
+ 20 21 22
38
+ ```
39
+
40
+ $ cut -f1,2 sample.tsv
41
+
42
+ ```
43
+ f0 f1
44
+ 0 1
45
+ 5 6
46
+ 10 11
47
+ 15 16
48
+ 20 21
49
+ ```
50
+
Original file line number Diff line number Diff line change 18
18
print (line .split (delemeter )[int (field_num )- 1 ])
19
19
else :
20
20
file_name = sys .argv [2 ]
21
- #print(field, field_num, file_name)
22
-
23
21
file_content = open (file_name )
24
- for line in file_content .readlines ():
25
- print (line .split ("\t " )[int (field_num )- 1 ])
22
+ print (field , field_num , file_name )
23
+
24
+ field_num_list = []
25
+ if (len (field_num ) >= 2 ):
26
+ ## This is for supporting the case for cut -f1,2 sample.tsv & cut -d, -f"1 2" fourchords.csv
27
+ field_num_list = field_num .split (field_num [1 ]) # split on the basis of delemeter
28
+ for line in file_content .readlines ():
29
+ selected_columns = []
30
+ for columnnum in field_num_list :
31
+ selected_columns .append (line .split ("\t " )[int (columnnum )- 1 ])
32
+ print ("\t " .join (selected_columns ))
33
+ else :
34
+ ## below section is to print based on the default delemeter tab. E.X: cut -f2 sample.tsv
35
+ for line in file_content .readlines ():
36
+ print (line .split ("\t " )[int (field_num )- 1 ])
37
+
38
+
39
+
40
+
You can’t perform that action at this time.
0 commit comments