The statement I provided should handle special characters in the find and for loop statements. How the files are processed after finding them is up to the code within the for loop. File names should not include new line characters...at least I have yet to encounter one. If you have a suggestion for dealing with such an occurrence, please include it so we can all learn from it.
Thanks.
Quote:
Originally Posted by dunkar70
If by special characters you mean IFS characters, it will not, and it cannot be made to do so. The shell splits the results of the find command on IFS characters (by default, space, tab, and newline). If a filename contains any of those characters, it is broken up into words and each word is fed to the loop one at a time. The only way to prevent the shell from field splitting the results of a command substitution is to double quote it, but that would always result in one word, and a loop that will only execute once (which isn't much of a loop, ).
An illustrative example using spaces, which aren't that uncommon:
Note how the filename was mangled because it was split into three words. A better approach:
That will handle everything except newlines in filenames, since find injects newlines into its output stream as a delimiter. While I agree that people using newlines in filenames deserve all the pain that a posix-compliant environment can throw at them, if such names need to be handled, the only posix-compliant solution I know of for a situation that requires recursion is (where myscript.sh is a shell script that does whatever needs doing with the filenames passed to it via positional parameters):
Although it's not posix-compliant, the following is likely supported:
myscript.sh can then safely loop through the filenames, even if they contain a newline, using the following for loop:
(when the for loop's list is absent, it defaults to "$@")
Regards,
Alister
---------- Post updated at 02:43 PM ---------- Previous update was at 02:28 PM ----------
Quote:
Originally Posted by pantelis
im trying this in csh but it doesn't seem to work.
btw
im checking the second parameter, like this
if($argv[2] == "-r") then
search in all the sub-folders of that folder
endif
Apologies, pantelis. It seems that your thread took a detour into bourne sh land, in no small part because of my comments. If you can switch away from csh to sh, you'll find that there are MANY more people able to provide assistance.
@alister, thanks for clarifying. I guess I generally use camelBack naming convention so I have not come across this before. I think I also assumed (I know, my bad) that the for loop would only use one delimiter. Since the find command would return multiple files, the new line would be the file name delimiter and the spaces would be used as part of the name.
wget -x -i link.txt
The above downloads and create unique entries for the 97 links in the text file. However, each new file is saved as CM080 with a FILE extention. Is there a way to convert each file in that directory to a .txt? The 97 files are in... (12 Replies)
I'm sure this has been asked many times, but a search didn't turn up a definitive best method for this (if there ever is such a thing).
I have been using rsync to back up my main data directory, but I have accumulated a large number of older backups that I don't need. All of the files I don't... (14 Replies)
I need to write a script to :
list files with *.i extension in a directory and all its subdirectories + 30days old, save it in a file and then remove (2 Replies)
Hi,
My requirement is,there is a directory location like:
:camp/current/
In this location there can be different flat files that are generated in a single day with same header and the data will be different, differentiated by timestamp, so i need to verify how many files are generated... (10 Replies)
Hi there,
I have around 145,000 files with no file extension in this directory - /home/adams/29:
The file name varies but all end with a number from 0 - 9,
e.g. TTFILE_BAT_235496, CCNHATA_RFC_23455
I want to give all these 145,000 .txt extension.
Please how do I do that?
Thanks (2 Replies)
Hi all,
i have 2 directory of files, the first directory(ext1directory) contain files of extension .ext1 and the second directory(allextdirectory) contains files of multiple extensions (.ext1,.ext2,.ext3,..)
so i want to copy the files from directory 2(allextdirectory) that have the same name... (8 Replies)
I'm rusty with cp, so I was wondering: is it possible to cp all the .doc files in a folder and make them .txt files? Can you use cp to do that? (3 Replies)
I've been able to find all the extensionless files named photos using the command:
find /usr/local/apache/htdocs -name photos -print0
I need to copy those files to the name photos.php in their same directory.
I've found a bunch of xarg examples for moving to other directories but I wasn't... (7 Replies)
I have many types of files (Eg: *.log, *.rpt, *.txt, *.dat) in a directory. I want to display all file types except *.txt.
What is the command to display all files except "*.txt" (9 Replies)
Hi,
I need one line command to display all files that ends with .scr.
Example: In a directory I have 10 files, out of that 4 files have filetype extension .dat and 4 files with .scr and 2 files with .txt.... In this i want to display only files that ends with .scr.
I tried some commands,... (2 Replies)