Re: basic command pipe question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Don Russell wrote:

[snip]
So the most *robust* would be:

ls -a | grep --null -iE \\.zip$ | xargs --null rm -f

That would erase all file ending with any .zip in any combination of upper and lower case characters, even if the file namehave any embedded spaces or other "special" characters.


Interestingly enough, I tried that expecting it to do exactly what I wanted, with no worries regarding the number of files etc.

to test it quickly:
touch this.zip
touch that.ZiP

ls | grep --null -iE \\.zip$ | xargs --null rm

Instead of being prompted to erase the two files, I got an error message from rm:
rm: cannot remove `that.ZiP\nthis.zip\n': No such file or directory

(I'll use rm -f when I've got this working properly.... but or testing I just want to be prompted)

What is wrong with the above command? man grep explains the --null option terminates the line with a null character instead of the usualy newline. And --null on xargs says lines are terminated by null, so args with embedded blanks etc work properly.

It appears grep is adding the null character, but in ADDITION to the newline.

What did work though was adding another command in the chain to tr '\n' \000'

but that should not be necessary? Have I discovered a bug in grep? hmmm






[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux