Hello, on linux, in cli, I have a file of 134 lines. I want to split it in blocs of 10…
- User
Hello, on linux, in cli, I have a file of 134 lines. I want to split it in blocs of 10 lines. I would rather not generate 14 files ( 13 of 10 lines and one of 4 lines ) but I would rather have a function which returns me the Nth bloc of 10 lines. for example: get_nth_chunk /tmp/my_134_lines_files 3
Would return the 10 lines from the 30th to the 39th Could you help?
Assistant
Yes, you can achieve this by using bash scripting and the
sedcommand. Here's an example function that you can use:get_nth_chunk() { file="$1" nth="$2" start_line=$((nth-1)*10+1) end_line=$((nth*10)) sed -n "${start_line},${end_line}p" "$file" }
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.