I have an issue whenever I run this script. It gets the right word count of the file, but whenever I run it in the terminal it has unwanted spacing.
#!/bin/bash
char=$(cat $1 | wc -c)
echo "This file has $char characters in it."
nolines=$(cat $1 | tr -d "\n" | wc -c)
echo "This file has $nolines characters not counting the new line."
emptyline=$(grep -cv '\S' $1) echo "This file has $emptyline empty lines."
alphachar=$(tr -cd '[:alpha:]' < $1 | wc -c)
echo "This file has $alphachar alphanumeric characters."
Using a file with this in it called example_file
(this is the file under this, or the content of the file):
This is the first line
This is the second
This has the symbols @#$
there was just an empty line.
So whenever I run my script like ~/script.sh example_file
it gives an output of
This file has 93 characters in it.
This file has 88 characters not counting the new line.
This file has 1 empty lines.
This file has 70 alphanumeric characters.
I was expecting for the output to have no spacing in between.