Hi All,
I'm using KSH and am writing a small script that counts the lines of various files in several folders under one root folder.
Below is the script:
#!/usr/bin/ksh
common_path_in="/interface_in/rsc"
file_out="/interface_in/rsc/record_count.csv"
tot_rec_count=-1
act_rec_count=-1
echo ${common_path_in}
echo ${file_out}
echo ${tot_rec_count}
echo ${act_rec_count}
set -A folders horizon mysteryshopper rcc reference
echo ${folders[@]}
for i in ${folders[@]}
do echo ${common_path_in}
echo "${common_path_in}/$i"
echo `ls -1 ${common_path_in}/$i/*.csv`;done
Please find the output screenshot attached for your reference. Following are my questions regarding the output that I'm getting -
The output of the line marked in red is the problem:
common_path_in="/interface_in/rsc"
$i in first iteration is - ${folders[0]}=horizon
so I should get "/interface_in/rsc/horizon", but I'm getting "/horizonce/rsc/". horizon is coming at the beginning of the string.
Also I've noticed that, if I give line breaks before the loop, then I'm getting some error - 'unexpected `do' ' or something like this. Even I'm getting this error if I place 'do' and 'done' in a separate lines alone.
Could anyone of you please look into it and let me know where I'm doing wrong?
You've probably edited the script with a Microsoft editor such as Notepad.
Please post the output from this "sed" command which is designed to make control characters visible. A normal unix text file line terminator will be displayed as a dollar sign. One which has been edited with a Microsoft editor will also have carriage-return characters displayed as "\r".
sed -n l scriptname
Where "scriptname" is the name of your script file.
Now I've edited the script in vi and have done this identation change that you've suggested.
I'm getting the below output and error message -
/interface_in/rsc
/interface_in/rsc/record_count.csv
-1
-1
horizon mysteryshopper rcc reference
test.ksh: line 10: syntax error at line 17: `for' unmatched
Intially I was following indentation and line breaks, but I was getting this same error. When I remove all extra spaces and indentation then this error was not there.
Please advise.
Regards,
Jagari
---------- Post updated at 11:58 AM ---------- Previous update was at 11:57 AM ----------
okay, let me try this... getting back to you after changing it...
---------- Post updated at 12:03 PM ---------- Previous update was at 11:58 AM ----------