gpt-4-turbo-2024-04-09· OpenAI
WildChat-4.8M (AI2)
I want a bash script to convert coordinates from a text file into an SVG file. The…
- User
I want a bash script to convert coordinates from a text file into an SVG file. The coordinates in my input text file are closed polygonal shapes, they contain whole and decimal numbers, use them directly as points in SVG elements. make sure that the script is fast and is parallelizing the processing of lines. Don't show any explanation
- Assistant
#!/bin/bash input_file=$1 output_file=$2 # Check if both input and output files are provided if [[ -z "$input_file" || -z "$output index_file" ]]; then echo "Usage: $0 input_file output_file" exit 1 fi # Create the SVG header echo '<svg xmlns="http://www.w3.org/2000/svg" version="1.1">' > $output_file # Process the input file in parallel using GNU Parallel cat $input_file | parallel --pipe --block 10K --will-cite --keep-order ' while read line; do # Forming the polygon points from space-separated values points=$(echo "$line" | sed "s/ /\ L/g; s/^/M /; s/$/ Z/") # Echoing SVG polygon element for each line echo "<path d=\"$points\" style=\"fill:none;stroke:black;stroke-width:1\" />" done ' >> $output_file # Close the SVG file echo '</svg>' >> $output_file