Last active
December 15, 2015 21:29
-
-
Save simonewebdesign/5326475 to your computer and use it in GitHub Desktop.
Bash script that joins two or more files in a single 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 | |
# Bash utility that joins every file provided as argument | |
# and outputs a new file called output.txt. | |
# bash trap function is executed when CTRL+C is pressed | |
trap quitprogram INT | |
quitprogram() { | |
echo -e "CTRL+C Detected!\nExiting..." | |
exit | |
} | |
echo -n "Creating output.txt file... " | |
if [ -f output.txt ]; then | |
echo "it already exists." | |
else | |
touch output.txt | |
echo "done." | |
fi | |
for file in "$@"; do | |
echo -n "Joining $file... " | |
cat $file >> output.txt | |
#sleep 1 | |
echo "done." | |
done | |
echo "Success! Your files have been joined into output.txt." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment