Created
July 23, 2024 19:43
-
-
Save leogdion/7d6ab03a7d64a04be6329f56ecbda441 to your computer and use it in GitHub Desktop.
Split Swift File by Brackets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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