remove the lines in CSV that contain specific pattern on the second field
Clash Royale CLAN TAG#URR8PPP
up vote
1
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
1
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
5 mins ago
add a comment |Â
up vote
1
down vote
favorite
up vote
1
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 3 hours ago
Jeff Schaller
32.3k849109
32.3k849109
asked 4 hours ago
yael
2,0361145
2,0361145
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
5 mins ago
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
5 mins ago
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
5 mins ago
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
5 mins ago
add a comment |Â
3 Answers
3
active
oldest
votes
up vote
5
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
3 hours ago
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
3 hours ago
add a comment |Â
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
5
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
5
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
5
down vote
accepted
up vote
5
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 2 hours ago
answered 3 hours ago
ñÃÂsýù÷
15.6k92563
15.6k92563
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 3 hours ago
glenn jackman
47.4k265103
47.4k265103
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
3 hours ago
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
3 hours ago
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
3 hours ago
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
3 hours ago
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 3 hours ago
Javier Salas
1115
1115
2
What does this do if "content" is in the third position of a line?
â Christian Gibbons
3 hours ago
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
3 hours ago
add a comment |Â
2
What does this do if "content" is in the third position of a line?
â Christian Gibbons
3 hours ago
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
3 hours ago
2
2
What does this do if "content" is in the third position of a line?
â Christian Gibbons
3 hours ago
What does this do if "content" is in the third position of a line?
â Christian Gibbons
3 hours ago
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
3 hours ago
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
3 hours ago
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
5 mins ago