I am trying to write a script that would count the number of columns in a file. However, I don't know what the name of the file will be. I am trying to create a file called tempfile which has the information from the argument catted into it.
Here is the script that I have so far for the script called columnCounter:
#!/bin/bash read colNumber count=0 for i in $colNumber do count=`expr $count + 1' done echo "column number: $count"
The above code works as long as I have a file name with information and type it into the terminal in the following format: cat tempfile | columnCounter.
I tried adding the two lines of the below code to create a tempfile from the argument in the terminal and then cat the tempfile and pipe it to the columnCounter. But this does not work.
cat $1 > tempfile cat tempfile | columnCounter