remove n columns from CSV file [closed]
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
I have a csv file with data as below :
12,1234,28-07-2018 05:28:12.21,ABC60,3456,28-07-2018 05:28:12.21,AB60,7580,28-07-2018 06:28:12.21,PQ
I need to remove all date columns from the file through Unix.
linux shell-script csv
closed as unclear what you're asking by jasonwryan, Jeff Schaller, thrig, maulinglawns, ñÃÂsýù÷ Sep 6 at 2:19
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, itâÂÂs hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |Â
up vote
0
down vote
favorite
I have a csv file with data as below :
12,1234,28-07-2018 05:28:12.21,ABC60,3456,28-07-2018 05:28:12.21,AB60,7580,28-07-2018 06:28:12.21,PQ
I need to remove all date columns from the file through Unix.
linux shell-script csv
closed as unclear what you're asking by jasonwryan, Jeff Schaller, thrig, maulinglawns, ñÃÂsýù÷ Sep 6 at 2:19
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, itâÂÂs hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
5
What have you tried?
â jasonwryan
Sep 5 at 17:50
2
Are the positions of the date columns always the same?
â KM.
Sep 5 at 17:54
Yes position is always same for date column
â UnixLearner
Sep 6 at 9:00
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have a csv file with data as below :
12,1234,28-07-2018 05:28:12.21,ABC60,3456,28-07-2018 05:28:12.21,AB60,7580,28-07-2018 06:28:12.21,PQ
I need to remove all date columns from the file through Unix.
linux shell-script csv
I have a csv file with data as below :
12,1234,28-07-2018 05:28:12.21,ABC60,3456,28-07-2018 05:28:12.21,AB60,7580,28-07-2018 06:28:12.21,PQ
I need to remove all date columns from the file through Unix.
linux shell-script csv
linux shell-script csv
edited Sep 5 at 18:16
Jeff Schaller
33k849111
33k849111
asked Sep 5 at 17:49
UnixLearner
121
121
closed as unclear what you're asking by jasonwryan, Jeff Schaller, thrig, maulinglawns, ñÃÂsýù÷ Sep 6 at 2:19
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, itâÂÂs hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
closed as unclear what you're asking by jasonwryan, Jeff Schaller, thrig, maulinglawns, ñÃÂsýù÷ Sep 6 at 2:19
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, itâÂÂs hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
5
What have you tried?
â jasonwryan
Sep 5 at 17:50
2
Are the positions of the date columns always the same?
â KM.
Sep 5 at 17:54
Yes position is always same for date column
â UnixLearner
Sep 6 at 9:00
add a comment |Â
5
What have you tried?
â jasonwryan
Sep 5 at 17:50
2
Are the positions of the date columns always the same?
â KM.
Sep 5 at 17:54
Yes position is always same for date column
â UnixLearner
Sep 6 at 9:00
5
5
What have you tried?
â jasonwryan
Sep 5 at 17:50
What have you tried?
â jasonwryan
Sep 5 at 17:50
2
2
Are the positions of the date columns always the same?
â KM.
Sep 5 at 17:54
Are the positions of the date columns always the same?
â KM.
Sep 5 at 17:54
Yes position is always same for date column
â UnixLearner
Sep 6 at 9:00
Yes position is always same for date column
â UnixLearner
Sep 6 at 9:00
add a comment |Â
3 Answers
3
active
oldest
votes
up vote
2
down vote
Using awk
:
echo "12,1234,28-07-2018 05:28:12.21,ABC60,3456,28-07-2018 05:28:12.21,AB60,7580,28-07-2018 06:28:12.21,PQ" | awk -F ',' 'for (i=1;i<=NF;i++) if($i !~ "-") printf "%s,",$i'
12,1234,ABC60,3456,AB60,7580,PQ,
- prints the columns which are not having
-
Thank you so much. It worked for me
â UnixLearner
Sep 12 at 6:34
add a comment |Â
up vote
2
down vote
Assuming there are no embedded commas inside a comma-delimited field, and that you want to remove columns 3, 6 and 9.
$ cut -d, -f1,2,4,5,7,8,10 <file
12,1234,ABC60,3456,AB60,7580,PQ
The cut
command extracts the given columns out of a file. By default, tabs are used as column delimiters, but with -d,
we set the delimiter to a comma. The -f
option takes the column numbers (or ranges of column numbers) that are to be extracted.
Using csvcut
from CSVkit, which is a real CSV parser, we can also handle fields which contains embedded commas:
$ csvcut -c 1,2,4,5,7,8,10 file
12,1234,ABC60,3456,AB60,7580,PQ
This tool also handles cutting on column names if the file has headers for each column.
add a comment |Â
up vote
1
down vote
Albeit not awk
, but...
tr ',' 'n' < csv | grep -E -v '^[0-9]2-[0-9]2-[0-9]4' | tr 'n' ','
12,1234,ABC60,3456,AB60,7580,PQ,
add a comment |Â
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
Using awk
:
echo "12,1234,28-07-2018 05:28:12.21,ABC60,3456,28-07-2018 05:28:12.21,AB60,7580,28-07-2018 06:28:12.21,PQ" | awk -F ',' 'for (i=1;i<=NF;i++) if($i !~ "-") printf "%s,",$i'
12,1234,ABC60,3456,AB60,7580,PQ,
- prints the columns which are not having
-
Thank you so much. It worked for me
â UnixLearner
Sep 12 at 6:34
add a comment |Â
up vote
2
down vote
Using awk
:
echo "12,1234,28-07-2018 05:28:12.21,ABC60,3456,28-07-2018 05:28:12.21,AB60,7580,28-07-2018 06:28:12.21,PQ" | awk -F ',' 'for (i=1;i<=NF;i++) if($i !~ "-") printf "%s,",$i'
12,1234,ABC60,3456,AB60,7580,PQ,
- prints the columns which are not having
-
Thank you so much. It worked for me
â UnixLearner
Sep 12 at 6:34
add a comment |Â
up vote
2
down vote
up vote
2
down vote
Using awk
:
echo "12,1234,28-07-2018 05:28:12.21,ABC60,3456,28-07-2018 05:28:12.21,AB60,7580,28-07-2018 06:28:12.21,PQ" | awk -F ',' 'for (i=1;i<=NF;i++) if($i !~ "-") printf "%s,",$i'
12,1234,ABC60,3456,AB60,7580,PQ,
- prints the columns which are not having
-
Using awk
:
echo "12,1234,28-07-2018 05:28:12.21,ABC60,3456,28-07-2018 05:28:12.21,AB60,7580,28-07-2018 06:28:12.21,PQ" | awk -F ',' 'for (i=1;i<=NF;i++) if($i !~ "-") printf "%s,",$i'
12,1234,ABC60,3456,AB60,7580,PQ,
- prints the columns which are not having
-
answered Sep 5 at 18:10
msp9011
3,46643862
3,46643862
Thank you so much. It worked for me
â UnixLearner
Sep 12 at 6:34
add a comment |Â
Thank you so much. It worked for me
â UnixLearner
Sep 12 at 6:34
Thank you so much. It worked for me
â UnixLearner
Sep 12 at 6:34
Thank you so much. It worked for me
â UnixLearner
Sep 12 at 6:34
add a comment |Â
up vote
2
down vote
Assuming there are no embedded commas inside a comma-delimited field, and that you want to remove columns 3, 6 and 9.
$ cut -d, -f1,2,4,5,7,8,10 <file
12,1234,ABC60,3456,AB60,7580,PQ
The cut
command extracts the given columns out of a file. By default, tabs are used as column delimiters, but with -d,
we set the delimiter to a comma. The -f
option takes the column numbers (or ranges of column numbers) that are to be extracted.
Using csvcut
from CSVkit, which is a real CSV parser, we can also handle fields which contains embedded commas:
$ csvcut -c 1,2,4,5,7,8,10 file
12,1234,ABC60,3456,AB60,7580,PQ
This tool also handles cutting on column names if the file has headers for each column.
add a comment |Â
up vote
2
down vote
Assuming there are no embedded commas inside a comma-delimited field, and that you want to remove columns 3, 6 and 9.
$ cut -d, -f1,2,4,5,7,8,10 <file
12,1234,ABC60,3456,AB60,7580,PQ
The cut
command extracts the given columns out of a file. By default, tabs are used as column delimiters, but with -d,
we set the delimiter to a comma. The -f
option takes the column numbers (or ranges of column numbers) that are to be extracted.
Using csvcut
from CSVkit, which is a real CSV parser, we can also handle fields which contains embedded commas:
$ csvcut -c 1,2,4,5,7,8,10 file
12,1234,ABC60,3456,AB60,7580,PQ
This tool also handles cutting on column names if the file has headers for each column.
add a comment |Â
up vote
2
down vote
up vote
2
down vote
Assuming there are no embedded commas inside a comma-delimited field, and that you want to remove columns 3, 6 and 9.
$ cut -d, -f1,2,4,5,7,8,10 <file
12,1234,ABC60,3456,AB60,7580,PQ
The cut
command extracts the given columns out of a file. By default, tabs are used as column delimiters, but with -d,
we set the delimiter to a comma. The -f
option takes the column numbers (or ranges of column numbers) that are to be extracted.
Using csvcut
from CSVkit, which is a real CSV parser, we can also handle fields which contains embedded commas:
$ csvcut -c 1,2,4,5,7,8,10 file
12,1234,ABC60,3456,AB60,7580,PQ
This tool also handles cutting on column names if the file has headers for each column.
Assuming there are no embedded commas inside a comma-delimited field, and that you want to remove columns 3, 6 and 9.
$ cut -d, -f1,2,4,5,7,8,10 <file
12,1234,ABC60,3456,AB60,7580,PQ
The cut
command extracts the given columns out of a file. By default, tabs are used as column delimiters, but with -d,
we set the delimiter to a comma. The -f
option takes the column numbers (or ranges of column numbers) that are to be extracted.
Using csvcut
from CSVkit, which is a real CSV parser, we can also handle fields which contains embedded commas:
$ csvcut -c 1,2,4,5,7,8,10 file
12,1234,ABC60,3456,AB60,7580,PQ
This tool also handles cutting on column names if the file has headers for each column.
edited Sep 5 at 22:04
answered Sep 5 at 19:54
Kusalananda
107k14209331
107k14209331
add a comment |Â
add a comment |Â
up vote
1
down vote
Albeit not awk
, but...
tr ',' 'n' < csv | grep -E -v '^[0-9]2-[0-9]2-[0-9]4' | tr 'n' ','
12,1234,ABC60,3456,AB60,7580,PQ,
add a comment |Â
up vote
1
down vote
Albeit not awk
, but...
tr ',' 'n' < csv | grep -E -v '^[0-9]2-[0-9]2-[0-9]4' | tr 'n' ','
12,1234,ABC60,3456,AB60,7580,PQ,
add a comment |Â
up vote
1
down vote
up vote
1
down vote
Albeit not awk
, but...
tr ',' 'n' < csv | grep -E -v '^[0-9]2-[0-9]2-[0-9]4' | tr 'n' ','
12,1234,ABC60,3456,AB60,7580,PQ,
Albeit not awk
, but...
tr ',' 'n' < csv | grep -E -v '^[0-9]2-[0-9]2-[0-9]4' | tr 'n' ','
12,1234,ABC60,3456,AB60,7580,PQ,
answered Sep 5 at 19:31
maulinglawns
6,12621225
6,12621225
add a comment |Â
add a comment |Â
5
What have you tried?
â jasonwryan
Sep 5 at 17:50
2
Are the positions of the date columns always the same?
â KM.
Sep 5 at 17:54
Yes position is always same for date column
â UnixLearner
Sep 6 at 9:00