![]() ![]() I thought I was a relatively advanced Bash user, but I cannot find a simple magic incantation to get this to work. this is a file.xml ends up trying to run grep on each piece (./this, is, a and file.xml). Because while reads from a file instead of a pipe, your loop can set variables that are accessible from outside the scope. If you really want something faster and without the need for Python, take zargs and yargs as prototypes and rewrite in C++ or C. In all cases I've tried (see below), Bash splits the filenames at the spaces so, for example, a line in listOfFiles.txt containing a name like. The first < indicates that youre reading from a file, and the <(find.) is replaced by a filename (usually a handle to a pipe) that returns the output from find directly. (Here 203 is just a placeholder, of course, and using a strange number like 203 makes it clear that this number has no other significance.) |grep "FooBar"|yargs -l 203 cp -after ~/foo/bar With yargs as written (and Python 3 installed) you can type: find. a dir - file with spaces.txt - b dir - another file with spaces.txt - yet another file with spaces. I played with this a little, started contemplating modifying xargs, and realised that for the kind of use case we're talking about here, a simple reimplementation in Python is a better idea.įor one thing, having ~80 lines of code for the whole thing means it is easy to figure out what is going on, and if different behaviour is required, you can just hack it into a new script in less time than it takes to get a reply on somewhere like Stack Overflow. Can anyone recommend a safe solution to recursively replace spaces with underscores in file and directory names starting from a given root directory For example: tree. Read a File with spaces in filename You can use 'cat' command or open the document using your preferred text editor such as vim, nano or gedit. name '*FooBar*' -exec cp -t /tmp - | sed 's/./\\&/g' | xargs the script into some directory in your $PATH and don't forget to What I try (this one retrieve all the files in the directory and contain spaces, but only the existing ones, i need to find the non existing too): find. If you want to view such a file with space in the file name, use the same principle of enclosing the file names inside the quotation marks. If you read the shell manual carefully, it basically says that variables (and a few other things) get expanded THEN it goes looking for spaces. The reason you got a problem is because of the process the shell uses to construct command lines. name \. Once again, note the avoidance of braces for a simple variable expansion. name \.xml -print0 xargs -0 grep -lZ ' ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |