Skip to content

Instantly share code, notes, and snippets.

@forestbaker
Last active December 5, 2015 08:02
Show Gist options
  • Save forestbaker/3e80819cdbb2ea78613f to your computer and use it in GitHub Desktop.
Save forestbaker/3e80819cdbb2ea78613f to your computer and use it in GitHub Desktop.
useful use of cat
#!/bin/bash
clear
#set -xv
HOME="$(pwd -P)"
#
printf '\n%s\n' 'cat is a core binary utility that is used to "concatenate" files'
#man cat
#
printf '\n\n%s\n\n' 'create things filled with no thing'
[ -f ./file1 -a -f ./file2 ] && rm -f ./file[1,2] || touch ./file1 ./file2
wc ./file1 ./file2
#
printf '\n\n%s\n' 'add soul to file1 with cat'
cat <<jazzzz > ./file1
i'm a real cool cat ...
with a lot of this
and a lot of that
so come on in
and get down!
jazzzz
#
printf '\n\n%s\n\n' 'add whiskers to file2'
cat <<'ASCIIcat' > ./file2
/\___/\
) (
=\ /=
) (
/ \
) (
/ \
\ /
jgs \__ __/
))
//
((
\)
ASCIIcat
#
printf '\n\n%s\n\n' '|- Contents of file1 -|'
cat ./file1
#
printf '\n%s\n\n' '|- Contents of file2 -|'
cat ./file2
wc ./file[1,2]
#
cat ./file[1,2] > ./file3
printf '\n%s\n\n' '|- Contents of file3 -|'
cat ./file3
wc ./file[1,2,3]
#
printf '\n%s\n\n' 'Take the contents of all three files'
printf '\n%s\n\n' 'and overwrite the contents of the 3rd'
cat <<( cat ./file[1,2,3] ) > ./file3
wc ./file[1,2,3]
printf '\n%s\n\n' ' ... and cat also does this ... '
cat -n ./file3
#
# clean up
rm -f ./file[1,2,3]
#
echo
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment