remove the lines in CSV that contain specific pattern on the second field
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
How to remove the lines in .csv file that second field contain the word content
?
example :
ams-hbase-log4j,content:n#LicensedtotheApacheSoftwareFoundation(ASF)underonen#ormorecontributorlicenseagreements
ams-log4j,content:n#n#LicensedtotheApacheSoftwareFoundation(ASF)underonen#ormorecontributorlicenseagreements.
ams-site,timeline.metrics.cache.size:150,
expected output
ams-site,timeline.metrics.cache.size:150,
linux text-processing sed perl csv
add a comment |Â
up vote
0
down vote
favorite
How to remove the lines in .csv file that second field contain the word content
?
example :
ams-hbase-log4j,content:n#LicensedtotheApacheSoftwareFoundation(ASF)underonen#ormorecontributorlicenseagreements
ams-log4j,content:n#n#LicensedtotheApacheSoftwareFoundation(ASF)underonen#ormorecontributorlicenseagreements.
ams-site,timeline.metrics.cache.size:150,
expected output
ams-site,timeline.metrics.cache.size:150,
linux text-processing sed perl csv
Warning: This specific example does not appear to have any embedded commas in the first field. For example, in"blah, blah",content:n ...
, the comma inside the double-quotes is not a field separator. If someone reads this and has to deal with those, the answer provided here will not work correctly. Parsing CSV correctly to deal with such non-separating commas is tricky business.
â Monty Harder
Sep 13 at 21:55
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
How to remove the lines in .csv file that second field contain the word content
?
example :
ams-hbase-log4j,content:n#LicensedtotheApacheSoftwareFoundation(ASF)underonen#ormorecontributorlicenseagreements
ams-log4j,content:n#n#LicensedtotheApacheSoftwareFoundation(ASF)underonen#ormorecontributorlicenseagreements.
ams-site,timeline.metrics.cache.size:150,
expected output
ams-site,timeline.metrics.cache.size:150,
linux text-processing sed perl csv
How to remove the lines in .csv file that second field contain the word content
?
example :
ams-hbase-log4j,content:n#LicensedtotheApacheSoftwareFoundation(ASF)underonen#ormorecontributorlicenseagreements
ams-log4j,content:n#n#LicensedtotheApacheSoftwareFoundation(ASF)underonen#ormorecontributorlicenseagreements.
ams-site,timeline.metrics.cache.size:150,
expected output
ams-site,timeline.metrics.cache.size:150,
linux text-processing sed perl csv
linux text-processing sed perl csv
edited Sep 13 at 18:10
Jeff Schaller
33.1k849111
33.1k849111
asked Sep 13 at 18:00
yael
2,0391345
2,0391345
Warning: This specific example does not appear to have any embedded commas in the first field. For example, in"blah, blah",content:n ...
, the comma inside the double-quotes is not a field separator. If someone reads this and has to deal with those, the answer provided here will not work correctly. Parsing CSV correctly to deal with such non-separating commas is tricky business.
â Monty Harder
Sep 13 at 21:55
add a comment |Â
Warning: This specific example does not appear to have any embedded commas in the first field. For example, in"blah, blah",content:n ...
, the comma inside the double-quotes is not a field separator. If someone reads this and has to deal with those, the answer provided here will not work correctly. Parsing CSV correctly to deal with such non-separating commas is tricky business.
â Monty Harder
Sep 13 at 21:55
Warning: This specific example does not appear to have any embedded commas in the first field. For example, in
"blah, blah",content:n ...
, the comma inside the double-quotes is not a field separator. If someone reads this and has to deal with those, the answer provided here will not work correctly. Parsing CSV correctly to deal with such non-separating commas is tricky business.â Monty Harder
Sep 13 at 21:55
Warning: This specific example does not appear to have any embedded commas in the first field. For example, in
"blah, blah",content:n ...
, the comma inside the double-quotes is not a field separator. If someone reads this and has to deal with those, the answer provided here will not work correctly. Parsing CSV correctly to deal with such non-separating commas is tricky business.â Monty Harder
Sep 13 at 21:55
add a comment |Â
3 Answers
3
active
oldest
votes
up vote
6
down vote
accepted
With sed
and to remove the lines that second field contains content
, you could do:
sed '/^[^,]*,[^,]*content/d' infile
or to remove the lines which second field stars with content
:
sed '/^[^,]*,content/d' infile
add a comment |Â
up vote
4
down vote
awk -F, '$2 !~ /content/' file.csv
If you mean "remove lines where the 2nd field starts with "content", then
awk -F, '$2 !~ /^content/' file.csv
add a comment |Â
up vote
-1
down vote
basically what you can do in the easiest way is:
cat "/dir/yourfile.csv" | grep -v ",content:" > newcsvfile.csv
if you want to use the same file name then you can do:
cat "/dir/yourfile.csv" | grep -v ",content:" > tmpfile && mv tmpfile "/dir/yourfile.csv"
2
What does this do if "content" is in the third position of a line?
â Christian Gibbons
Sep 13 at 18:07
that's an assumption if "content:" word will be only in the 2nd field, if it is in different field then the solution would not work and would be different
â Javier Salas
Sep 13 at 18:10
add a comment |Â
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
6
down vote
accepted
With sed
and to remove the lines that second field contains content
, you could do:
sed '/^[^,]*,[^,]*content/d' infile
or to remove the lines which second field stars with content
:
sed '/^[^,]*,content/d' infile
add a comment |Â
up vote
6
down vote
accepted
With sed
and to remove the lines that second field contains content
, you could do:
sed '/^[^,]*,[^,]*content/d' infile
or to remove the lines which second field stars with content
:
sed '/^[^,]*,content/d' infile
add a comment |Â
up vote
6
down vote
accepted
up vote
6
down vote
accepted
With sed
and to remove the lines that second field contains content
, you could do:
sed '/^[^,]*,[^,]*content/d' infile
or to remove the lines which second field stars with content
:
sed '/^[^,]*,content/d' infile
With sed
and to remove the lines that second field contains content
, you could do:
sed '/^[^,]*,[^,]*content/d' infile
or to remove the lines which second field stars with content
:
sed '/^[^,]*,content/d' infile
edited Sep 13 at 19:48
answered Sep 13 at 18:06
ñÃÂsýù÷
16k92563
16k92563
add a comment |Â
add a comment |Â
up vote
4
down vote
awk -F, '$2 !~ /content/' file.csv
If you mean "remove lines where the 2nd field starts with "content", then
awk -F, '$2 !~ /^content/' file.csv
add a comment |Â
up vote
4
down vote
awk -F, '$2 !~ /content/' file.csv
If you mean "remove lines where the 2nd field starts with "content", then
awk -F, '$2 !~ /^content/' file.csv
add a comment |Â
up vote
4
down vote
up vote
4
down vote
awk -F, '$2 !~ /content/' file.csv
If you mean "remove lines where the 2nd field starts with "content", then
awk -F, '$2 !~ /^content/' file.csv
awk -F, '$2 !~ /content/' file.csv
If you mean "remove lines where the 2nd field starts with "content", then
awk -F, '$2 !~ /^content/' file.csv
answered Sep 13 at 18:23
glenn jackman
48.2k365105
48.2k365105
add a comment |Â
add a comment |Â
up vote
-1
down vote
basically what you can do in the easiest way is:
cat "/dir/yourfile.csv" | grep -v ",content:" > newcsvfile.csv
if you want to use the same file name then you can do:
cat "/dir/yourfile.csv" | grep -v ",content:" > tmpfile && mv tmpfile "/dir/yourfile.csv"
2
What does this do if "content" is in the third position of a line?
â Christian Gibbons
Sep 13 at 18:07
that's an assumption if "content:" word will be only in the 2nd field, if it is in different field then the solution would not work and would be different
â Javier Salas
Sep 13 at 18:10
add a comment |Â
up vote
-1
down vote
basically what you can do in the easiest way is:
cat "/dir/yourfile.csv" | grep -v ",content:" > newcsvfile.csv
if you want to use the same file name then you can do:
cat "/dir/yourfile.csv" | grep -v ",content:" > tmpfile && mv tmpfile "/dir/yourfile.csv"
2
What does this do if "content" is in the third position of a line?
â Christian Gibbons
Sep 13 at 18:07
that's an assumption if "content:" word will be only in the 2nd field, if it is in different field then the solution would not work and would be different
â Javier Salas
Sep 13 at 18:10
add a comment |Â
up vote
-1
down vote
up vote
-1
down vote
basically what you can do in the easiest way is:
cat "/dir/yourfile.csv" | grep -v ",content:" > newcsvfile.csv
if you want to use the same file name then you can do:
cat "/dir/yourfile.csv" | grep -v ",content:" > tmpfile && mv tmpfile "/dir/yourfile.csv"
basically what you can do in the easiest way is:
cat "/dir/yourfile.csv" | grep -v ",content:" > newcsvfile.csv
if you want to use the same file name then you can do:
cat "/dir/yourfile.csv" | grep -v ",content:" > tmpfile && mv tmpfile "/dir/yourfile.csv"
answered Sep 13 at 18:06
Javier Salas
1115
1115
2
What does this do if "content" is in the third position of a line?
â Christian Gibbons
Sep 13 at 18:07
that's an assumption if "content:" word will be only in the 2nd field, if it is in different field then the solution would not work and would be different
â Javier Salas
Sep 13 at 18:10
add a comment |Â
2
What does this do if "content" is in the third position of a line?
â Christian Gibbons
Sep 13 at 18:07
that's an assumption if "content:" word will be only in the 2nd field, if it is in different field then the solution would not work and would be different
â Javier Salas
Sep 13 at 18:10
2
2
What does this do if "content" is in the third position of a line?
â Christian Gibbons
Sep 13 at 18:07
What does this do if "content" is in the third position of a line?
â Christian Gibbons
Sep 13 at 18:07
that's an assumption if "content:" word will be only in the 2nd field, if it is in different field then the solution would not work and would be different
â Javier Salas
Sep 13 at 18:10
that's an assumption if "content:" word will be only in the 2nd field, if it is in different field then the solution would not work and would be different
â Javier Salas
Sep 13 at 18:10
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f468860%2fremove-the-lines-in-csv-that-contain-specific-pattern-on-the-second-field%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Warning: This specific example does not appear to have any embedded commas in the first field. For example, in
"blah, blah",content:n ...
, the comma inside the double-quotes is not a field separator. If someone reads this and has to deal with those, the answer provided here will not work correctly. Parsing CSV correctly to deal with such non-separating commas is tricky business.â Monty Harder
Sep 13 at 21:55