Skip to content

Instantly share code, notes, and snippets.

@OhadRubin
Created May 18, 2025 05:21
Show Gist options
  • Save OhadRubin/13799bc39d4c216352f83a24283e4799 to your computer and use it in GitHub Desktop.
Save OhadRubin/13799bc39d4c216352f83a24283e4799 to your computer and use it in GitHub Desktop.

Strict Script Generation Task: File Partitioning with Shell Script

Primary Objective: Your sole task is to generate a shell script containing a function definition and a sequence of function calls designed to partition the provided original_file_content based on the rules specified in the explanation. This partitioning must be complete - all original content (except imports) must appear in exactly one output file, with no content omitted or duplicated.

Inputs Provided:

  1. - Text describing how the original file should be partitioned.
  2. <original_file_content>: The content of the file to be partitioned.

Instructions - Follow Sequentially and Precisely:

Step 1: Interpret the Explanation

  • Carefully read and interpret the explanation to determine:
    • The specific ranges of line numbers (start and end line for each chunk).
    • Which lines or chunks belong to which output file (implicitly determined by the structure or naming within the explanation).

Step 2: Determine Line Ranges

  • Using your interpretation from Step 1 and referencing the actual line count/structure of the <original_file_content>, calculate the exact numerical start and end line numbers for each distinct chunk that needs to be extracted.
  • Ensure your line ranges collectively cover the entire original file content (except imports), with no omissions or duplications, as required by Constraint D.

Step 3: Generate the Shell Script

  • Begin with the function definition:
    extract_to_file() {
        awk -v start="$1" -v end="$2" 'NR >= start && NR <= end' $INPUT_FILENAME >> $CURRENT_FILE
    }
    
  • Define the input filename variable:
    INPUT_FILENAME=sample_synth.py
    
  • For each output file and its associated line ranges:
    • Set the current file variable:
      CURRENT_FILE=output_filename.py
      
    • For each line range for this file, add a function call:
      extract_to_file start_line end_line
      

Step 4: Assemble the Final Script

  • Combine all the elements from Step 3 into a single shell script.
  • MUST: Order the commands logically. Group function calls targeting the same output file together.
  • MUST NOT: Include any extra lines, blank lines, or commentary between the function definition, variable assignments, and function calls in the final output script.

The final script MUST follow this general structure, but with calculated start/end values and appropriate output_fileX.py names based on your analysis of the inputs:```text extract_to_file() { awk -v start="$1" -v end="$2" 'NR >= start && NR <= end' $INPUT_FILENAME >> $CURRENT_FILE }

INPUT_FILENAME=sample_synth.py CURRENT_FILE=output_file1.py extract_to_file start_line1 end_line1 extract_to_file start_line2 end_line2 extract_to_file start_line3 end_line3 extract_to_file start_line4 end_line4 CURRENT_FILE=output_file2.py extract_to_file start_line5 end_line5 extract_to_file start_line6 end_line6 extract_to_file start_line7 end_line7 extract_to_file start_line8 end_line8

... continue for other output files ...

*This example shows the structure; you MUST replace the start_lineN and end_lineN with calculated line numbers and use appropriate 
filenames according to the explanation*.

**Critical Constraints:**

*   **Constraint A: Output ONLY Script:** Your final response **MUST** contain **ONLY** the generated 
plain text script. Do **NOT** include any introductory text, explanations, the input problem/explanation/
code, or the instructions themselves.
*   **Constraint B: Use ONLY AWK Format:** Use **ONLY** the specified `awk` command format shown in Step 3 
and the Example Output Structure. No other commands or variations are allowed.
*   **Constraint C: Filenames:** Use `original_filename.py` exactly. Use file names that match the 
partitions identified in the `{explanation}`.
*   **Constraint D: Complete Partitioning:** If one excludes import statements, the partitioning must 
cover all the remaining content from the original file. This is a partition in the mathematical sense - 
all original content (except imports) must appear in exactly one output file, with no content omitted or 
duplicated.

**Step 5: Verification Checklist (Internal Check)**
*   Before providing the final output, internally verify:
    *   Is the output a single block of plain text containing only the function definition and function calls?
    *   Does the script follow the exact structure with the function definition, INPUT_FILENAME, CURRENT_FILE variables, and extract_to_file function calls?
    *   Are the `start` and `end` values numerically correct based on the `{explanation}` and 
    `<original_file_content>`?
    *   Are the `CURRENT_FILE` values correctly determined and used for each group of function calls?
    *   Are the function calls grouped and ordered correctly by output file?
    *   Do the line ranges collectively satisfy Constraint D by completely partitioning the original file 
    (excluding imports) with no omissions or duplications?
    *   Is there *any* extra text or blank lines in the output? (There should NOT be).
    
    

The final script **MUST** follow this exact structure, but with calculated `start`/`end` values and appropriate output filenames based on your analysis of the inputs:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment