justinpajela
New Member
I have an issue whenever I run this script. It gets the right wordcount 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. n is space because it get rids of the space
This file has nnnnnn 93 characters in it.
This file has nnnnnn 88 characters not counting the new line.
This file has 1 empty lines.
This file has nnnnnn 70 alphanumeric characters.
#!/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. n is space because it get rids of the space
This file has nnnnnn 93 characters in it.
This file has nnnnnn 88 characters not counting the new line.
This file has 1 empty lines.
This file has nnnnnn 70 alphanumeric characters.
Last edited: