Script does not show the entire path

1

Code:

for i in 'find $1 -name $4 -type f' ; do  
path='readlink -f $4'  
words='cat "$i" | wc -w'  
echo "$path: $words palavras"  
done  

Prints:

/home/miglui/Desktop/SO/teste.txt: 14 palavras  
/home/miglui/Desktop/SO/teste.txt: 48 palavras  
/home/miglui/Desktop/SO/teste.txt: 29 palavras

Should Print:

/home/miglui/Desktop/SO/teste/1/teste.txt: 14 palavras  
/home/miglui/Desktop/SO/teste/2/teste.txt: 48 palavras  
/home/miglui/Desktop/SO/teste/teste.txt: 29 palavras

The code is not printing the entire path of the files. Where might the error be?

    
asked by anonymous 14.10.2014 / 20:54

2 answers

1

When you call the following line of the script:

path=$(readlink -f $4)

You are using the $ 4 argument. Although you have not put an example call to this script, I believe the $ 4 argument is the name of the file (example: test.txt). Only the file name will not work. It has to be the path of the file found by find.

In this case, you have to indicate the line:

path=$(readlink -f $i)

Since $ i is the iteration variable that contains the complete path of the file, and is what you use correctly to count the number of words with wc .

    
15.10.2014 / 05:47
0

Try

x=$"$(find -type f)"
for i in $x
    do echo -n "$i: "
    wc -w $i|cut -d " " -f1 -z
    echo -n " palavras"
    echo
done
    
21.09.2016 / 23:43