Hi,
I don't know hot to make this command work:
ls -laR | grep "^-" | awk '{print $9}'| grep "$.txt"
It should return the list of file .txt
It's important to search .txt at the end of the line, becouse some file name have "txt" in their name but have other extensions
It doen't work correctly.
The files with a space in their names are splitted and the file names are the last words, example:
MacBook-di-Mirko:~ mirko$ sudo ls -laR /Users/mirko/Unix | nawk '/^-/ && /.txt$/ {print $NF}'
Ga.txt
Me.txt
Rhye.txt
file.txt
lettera.txt
README.txt
I had already tryed, but doing so, the output could be:
Readme.txt
folder_txt.png
folder_txt.png
folder_txt.png
I had already tryed, but:
It works using it "stand-alone", for example:
MacBook-di-Mirko:unix mirko$ find /Users/mirko/Unix -type f -name '*.txt'
/Users/mirko/Unix/file.txt
/Users/mirko/Unix/lettera.txt
/Users/mirko/Unix/motion/README.txt
/Users/mirko/Unix/Radio Ga Ga.txt
/Users/mirko/Unix/Save Me.txt
/Users/mirko/Unix/Seven Seas Of Rhye.txt
It doesn't work using it in a for, for example:
MacBook-di-Mirko:unix mirko$ ./test.sh
/Users/mirko/Unix/file.txt
/Users/mirko/Unix/lettera.txt
/Users/mirko/Unix/motion/README.txt
/Users/mirko/Unix/Radio
Ga
Ga.txt
/Users/mirko/Unix/Save
Me.txt
/Users/mirko/Unix/Seven
Seas
Of
Rhye.txt
It split the file names with one or more spaces in their names
PS: the script is:
#!/bin/sh
for file in `find /Users/mirko/Unix -type f -name '*.txt'`
do
echo ${file}
done
what do you want to do with those *.txt files it finds?? I believe you don't just want to echo their names out. If that's the case, no need for a for loop/while loop because the find command displays to stdout. Otherwise, you can use -exec or xargs for simple task, or coupled with while loop for more complicated tasks