Skip to main content
added 56 characters in body
Source Link
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k

Using a tool specifically built for doing these sorts of things:

$ csvgrep -H -f BlockspamCLIs.txt -c 2 All_events.csv | tail -n +2
1,441236,20220909120909,test
5,2367890,20220909120909,test

The csvgrep utility is part of csvkit, and I use it here to extract all records from the header-less (-H) CSV file All_events.csv in which the second field (-c 2) matches any string in another file (-f BlockspamCLIs.txt).

Since the input file is a header-less CSV file, csvgrep will add a dummy header to the resulting CSV output, which we remove with tail (you could also use sed 1d or any other command that removes the first line and passes the rest on unmodified).

Since we use a CSV-aware tool, the input is not restricted to "simple" CSV data but would also work with input that contains fields with embedded commas, quotes and newlines.

This works even if the files are in DOS text format.

Using a tool specifically built for doing these sorts of things:

$ csvgrep -H -f BlockspamCLIs.txt -c 2 All_events.csv | tail -n +2
1,441236,20220909120909,test
5,2367890,20220909120909,test

The csvgrep utility is part of csvkit, and I use it here to extract all records from the header-less (-H) CSV file All_events.csv in which the second field (-c 2) matches any string in another file (-f BlockspamCLIs.txt).

Since the input file is a header-less CSV file, csvgrep will add a dummy header to the resulting CSV output, which we remove with tail (you could also use sed 1d or any other command that removes the first line and passes the rest on unmodified).

Since we use a CSV-aware tool, the input is not restricted to "simple" CSV data but would also work with input that contains fields with embedded commas, quotes and newlines.

Using a tool specifically built for doing these sorts of things:

$ csvgrep -H -f BlockspamCLIs.txt -c 2 All_events.csv | tail -n +2
1,441236,20220909120909,test
5,2367890,20220909120909,test

The csvgrep utility is part of csvkit, and I use it here to extract all records from the header-less (-H) CSV file All_events.csv in which the second field (-c 2) matches any string in another file (-f BlockspamCLIs.txt).

Since the input file is a header-less CSV file, csvgrep will add a dummy header to the resulting CSV output, which we remove with tail (you could also use sed 1d or any other command that removes the first line and passes the rest on unmodified).

Since we use a CSV-aware tool, the input is not restricted to "simple" CSV data but would also work with input that contains fields with embedded commas, quotes and newlines.

This works even if the files are in DOS text format.

Source Link
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k

Using a tool specifically built for doing these sorts of things:

$ csvgrep -H -f BlockspamCLIs.txt -c 2 All_events.csv | tail -n +2
1,441236,20220909120909,test
5,2367890,20220909120909,test

The csvgrep utility is part of csvkit, and I use it here to extract all records from the header-less (-H) CSV file All_events.csv in which the second field (-c 2) matches any string in another file (-f BlockspamCLIs.txt).

Since the input file is a header-less CSV file, csvgrep will add a dummy header to the resulting CSV output, which we remove with tail (you could also use sed 1d or any other command that removes the first line and passes the rest on unmodified).

Since we use a CSV-aware tool, the input is not restricted to "simple" CSV data but would also work with input that contains fields with embedded commas, quotes and newlines.