Skip to content

Instantly share code, notes, and snippets.

@simonewebdesign
Last active December 15, 2015 21:29
Show Gist options
  • Save simonewebdesign/5326475 to your computer and use it in GitHub Desktop.
Save simonewebdesign/5326475 to your computer and use it in GitHub Desktop.
Bash script that joins two or more files in a single one.
#!/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