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





--
fedora-list mailing list
fedora-list@xxxxxxxxxx
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
[Index of Archives]     [Older Fedora Users]     [Fedora Announce]     [Fedora Package Announce]     [EPEL Announce]     [Fedora Magazine]     [Fedora News]     [Fedora Summer Coding]     [Fedora Laptop]     [Fedora Cloud]     [Fedora Advisory Board]     [Fedora Education]     [Fedora Security]     [Fedora Scitech]     [Fedora Robotics]     [Fedora Maintainers]     [Fedora Infrastructure]     [Fedora Websites]     [Anaconda Devel]     [Fedora Devel Java]     [Fedora Legacy]     [Fedora Desktop]     [Fedora Fonts]     [ATA RAID]     [Fedora Marketing]     [Fedora Management Tools]     [Fedora Mentors]     [SSH]     [Fedora Package Review]     [Fedora R Devel]     [Fedora PHP Devel]     [Kickstart]     [Fedora Music]     [Fedora Packaging]     [Centos]     [Fedora SELinux]     [Fedora Legal]     [Fedora Kernel]     [Fedora OCaml]     [Coolkey]     [Virtualization Tools]     [ET Management Tools]     [Yum Users]     [Tux]     [Yosemite News]     [Gnome Users]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [Asterisk PBX]     [Fedora Sparc]     [Fedora Universal Network Connector]     [Libvirt Users]     [Fedora ARM]

  Powered by Linux