0

I have a large text file (>200MB). I want to read [n, n+a] bytes across all rows.

Suppose there are 1000 rows in the original text file. The output file would be 1000 rows.

What I know head -c349 original.text|tail -c28 > output.txt. However, this only outputs one row. How can I iterate though all rows?

Example: n = 2 a = 1.

Input: 123456 789789

Output: 23 89

  • What do you mean with [n, n+a] bytes? The a+1 bytes starting at position n on each line? A short sample input and output would help immensely. – ilkkachu Feb 8 '17 at 19:50
  • @ilkkachu An example has been added. – John Hass Feb 8 '17 at 19:53
2

The cut command will do it. For example, cut -c 10-12 will print characters 10 to 12 (inclusive) from each line of its input.

You can write cut -b 10-12 instead if you really mean bytes rather than characters.

  • Simple & elegant. – John Hass Feb 8 '17 at 19:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.