mtryingtocode
mtryingtocode

Reputation: 969

unix ksh getting number of lines from file

I'm using ksh and tested my script in a CentOS and Ubuntu VM and not having any issues. However when I migrated the file to a unix box the wc - l seems not working. Below is my script.

filelist=myfile.txt    
filecount=`wc -l ${filelist} | cut -d " " -f 1`
    echo "File count for $filelist is $filecount"

I have seen the permission and i has read for all users. What's causing it to have a problem in unix? Are there other ways in ksh to get the number of lines on a file? I'm thinking of using read line then just increment a variable for each as my last resort.

Upvotes: 0

Views: 555

Answers (1)

Henk Langeveld
Henk Langeveld

Reputation: 8456

Nothing appears to be wrong with your script, so there may an issue with your deployment. Perhaps a Windows desktop was involved in copying the text of the script? In that case each line would now include a CRLF as end of line marker instead of LF.

For me that gives the following output:

: No such file or directory

Upvotes: 1

Related Questions