Hi,
I have an unexpected bash scripting problem.
I'm writing a script in bash which finds files named SETUP.DTA. The prog. searches through a fs, and produces a list of their locations.
I assign an array variable to the first few letters in the file and then get the program to spit out the path location, and the file name. The program looks like this;
And the output looks like this:
[output]
[root@lxf 23:41:57 /scripts/sage] cat tek-tips\ example
cut: : No such file or directory
is in
co1 is in /home/tom/thispath&subdirs/7/SETUP.DTA
ac02 is in /home/tom/thispath&subdirs/8/SETUP.DTA
co6324 is in /home/tom/thispath&subdirs/9/SETUP.DTA
bunghole is in /home/tom/thispath&subdirs/1/SETUP.DTA
sdf is in /home/tom/thispath&subdirs/10/SETUP.DTA
asd is in /home/tom/thispath&subdirs/11/SETUP.DTA
sdjg is in /home/tom/thispath&subdirs/12/SETUP.DTA
rog is in /home/tom/thispath&subdirs/13/SETUP.DTA
sdf is in /home/tom/thispath&subdirs/14/SETUP.DTA
psjiodf is in /home/tom/thispath&subdirs/15/SETUP.DTA
s;dofih is in /home/tom/thispath&subdirs/16/SETUP.DTA
sd;ofh is in /home/tom/thispath&subdirs/2/SETUP.DTA
sdf[ p is in /home/tom/thispath&subdirs/3/SETUP.DTA
rt is in /home/tom/thispath&subdirs/4/SETUP.DTA
cox is in /home/tom/thispath&subdirs/5/SETUP.DTA
[/output]
I have 2 issues –
1. I do not know how to resolve the
[output]
cut: : No such file or directory
is in
[/output]
ie the first 2 lines of the output. The variable "${Array[$0]}" outputs a proper directory path which should not cause cut to have a problem.
2. Some of the subdirs’s pathnames have white space in them. I cannot make tr replace the “ “ with a “\ “ for the life of me.
If you want a set of the data to experiment on then please let me know, and I will provide you with one.
Please help me, I am truly stuck.
Many thanks,
Tom Jermy
I have an unexpected bash scripting problem.
I'm writing a script in bash which finds files named SETUP.DTA. The prog. searches through a fs, and produces a list of their locations.
I assign an array variable to the first few letters in the file and then get the program to spit out the path location, and the file name. The program looks like this;
Code:
#!/bin/sh
Array=(`find /home/thispath&subdirs -name SETUP.DTA`)
index=0
element_count=${#Array[@]}
while [ "$index" -lt "$element_count" ] # the -lt switch must mean is not equal to (the 0 index value)
do
var=`cut -b 2-53 "${Array[$element_count]}"
echo $var " is in " ${Array[$element_count]}
let "element_count = $element_count - 1"
done
And the output looks like this:
[output]
[root@lxf 23:41:57 /scripts/sage] cat tek-tips\ example
cut: : No such file or directory
is in
co1 is in /home/tom/thispath&subdirs/7/SETUP.DTA
ac02 is in /home/tom/thispath&subdirs/8/SETUP.DTA
co6324 is in /home/tom/thispath&subdirs/9/SETUP.DTA
bunghole is in /home/tom/thispath&subdirs/1/SETUP.DTA
sdf is in /home/tom/thispath&subdirs/10/SETUP.DTA
asd is in /home/tom/thispath&subdirs/11/SETUP.DTA
sdjg is in /home/tom/thispath&subdirs/12/SETUP.DTA
rog is in /home/tom/thispath&subdirs/13/SETUP.DTA
sdf is in /home/tom/thispath&subdirs/14/SETUP.DTA
psjiodf is in /home/tom/thispath&subdirs/15/SETUP.DTA
s;dofih is in /home/tom/thispath&subdirs/16/SETUP.DTA
sd;ofh is in /home/tom/thispath&subdirs/2/SETUP.DTA
sdf[ p is in /home/tom/thispath&subdirs/3/SETUP.DTA
rt is in /home/tom/thispath&subdirs/4/SETUP.DTA
cox is in /home/tom/thispath&subdirs/5/SETUP.DTA
[/output]
I have 2 issues –
1. I do not know how to resolve the
[output]
cut: : No such file or directory
is in
[/output]
ie the first 2 lines of the output. The variable "${Array[$0]}" outputs a proper directory path which should not cause cut to have a problem.
2. Some of the subdirs’s pathnames have white space in them. I cannot make tr replace the “ “ with a “\ “ for the life of me.
If you want a set of the data to experiment on then please let me know, and I will provide you with one.
Please help me, I am truly stuck.
Many thanks,
Tom Jermy