crownedzero
crownedzero

Reputation: 506

Split files linux and then grep

I'd like to split a file and grep each piece without writing them to indvidual files.

I've attempted a couple variations of split and grep and no such luck; any suggestions?

Something along the lines of: split -b SIZE filename | grep "string"

I've attempted grep/fgrep to find the string but my shell complains that the files are too large. See: use fgrep instead

Upvotes: 1

Views: 1184

Answers (1)

Alexander L. Belikoff
Alexander L. Belikoff

Reputation: 5721

There is no point in splitting the file if you plan to [linearly] search each of the pieces anyway (assuming that's the only thing you are doing with it). Consider running grep on the entire file.

If however you plan to utilize the fact that the file is split later on, then the typical way would be:

  • Create a temporary directory and step into it
  • Run split/csplit on the original file
  • Use for loop over written fragment to do your processing.

Upvotes: 1

Related Questions