1

I need help in unix scripting.

I am trying to use the head command in unix script but it's showing some errors.

for file_name in $(cat files.lst); 
do  
    echo $file_name
    file_count=$(head -n1 ${file_name} | awk -F '|' '{print NF}')
    echo `pwd`/${file_name}
    echo $file_count
done

I am trying to get the file name from the files list and get the column count for each file, but it's showing the file is not present.
The file, the script and the list file are all in the same directory.
I tried head -n1 ${file_name}, head -n1 $file_name in the script but did not get the result.

Can anyone please let me know if my logic is right and what is the mistake?

Rubén
  • 34,714
  • 9
  • 70
  • 166
Naveen
  • 11
  • 2
  • Try `set -x` at the beginning of your script, or `sh -x script`/`bash -x script` to debug. Is there any chance your list file has Windows-style line endings? That could cause "file not found" errors when the files appear to exist (the script will end up looking for file names like `\r` which of course won't exist). – nobody Oct 22 '14 at 18:54
  • You are right It shows \r after the file name in the error message.How to remove this.I tried using #!/bin/ksh at the beginning of the script.It doesnot help – Naveen Oct 22 '14 at 18:56
  • `dos2unix files.lst`. Good luck. – shellter Oct 22 '14 at 18:57

0 Answers0