Created
July 4, 2024 22:47
-
-
Save palaniraja/940e507a9b7b6833af6825c1f5a62a33 to your computer and use it in GitHub Desktop.
combine multiple .fbs to one
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 | |
# The output file | |
output_file='combined.fbs' | |
# Remove the output file if it already exists | |
if [ -f $output_file ]; then | |
rm $output_file | |
fi | |
# Variable to store the namespace | |
namespace="" | |
# Loop over all .fbs files in the current directory | |
for f in *.fbs | |
do | |
# Exclude the output file | |
if [ $f != $output_file ]; then | |
# Check if the file contains a namespace definition | |
if grep -q "^namespace" $f; then | |
# Extract the namespace and remove the trailing semicolon | |
namespace=$(grep "^namespace" $f | cut -d ' ' -f2 | tr -d ';') | |
fi | |
# Use grep to exclude lines that start with 'include' or 'namespace' | |
grep -v '^include\|^namespace' $f >> $output_file | |
# Append a newline to the output file to separate the contents of the .fbs files | |
printf "\n" >> $output_file | |
fi | |
done | |
# Prepend the namespace to the output file | |
printf "namespace $namespace;\n$(cat $output_file)" > $output_file | |
printf "Combined .fbs files into $output_file\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
PROMPT
original converstation