Skip to content

Instantly share code, notes, and snippets.

@leogdion
Created July 23, 2024 19:43
Show Gist options
  • Save leogdion/7d6ab03a7d64a04be6329f56ecbda441 to your computer and use it in GitHub Desktop.
Save leogdion/7d6ab03a7d64a04be6329f56ecbda441 to your computer and use it in GitHub Desktop.
Split Swift File by Brackets
#!/bin/bash
# Check if a filename was provided
if [ $# -ne 1 ]; then
echo "Usage: $0 <filename>"
exit 1
fi
filename=$1
# Check if the file exists
if [ ! -f "$filename" ]; then
echo "File $filename does not exist."
exit 1
fi
# Split the file based on lines containing only '}'
awk '{
if ($0 ~ /^}$/) {
print $0 > (output_file_prefix "" file_number ".swift")
file_number++
} else {
print $0 > (output_file_prefix "" file_number ".swift")
}
}' output_file_prefix="part" file_number=1 "$filename"
echo "Splitting completed."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment