Berkeley CSUA MOTD:Entry 35028
Berkeley CSUA MOTD
 
WIKI | FAQ | Tech FAQ
http://csua.com/feed/
2025/05/26 [General] UID:1000 Activity:popular
5/26    

2004/11/22-23 [Computer/SW/Languages/Perl] UID:35028 Activity:kinda low
11/22   How do I get find to return me a list of files with every questionable
        character escaped by a backslash?  ', ", ?, <space>, etc are
        "questionable"
        \_ find . -print0 | perl -0pe 'chop;s#[^\w/.,-]#\\$&#g;$_.="\n"'
           (assumes you have perl and find which supports print0; both common
           on modern boxes; also i specified the list of "OK" characters rather
           than questionable ones; i think it's safer; note also that -print0
           by itself may have been what you were looking for, since this will
           possibly give you results like this:
           file\ with\ newline\
           in\ it.txt
           (the newline is blackslashed, but that may or may not help you)
           --dbushong
        \_ Pipe it through perl -ne 'print quotemeta $_'
        \_ Pipe it through perl -ne 'print quotemeta $_' --scotsman
           \_ or just perl -pe 'print quotemeta'
              \_ Er, no. perl -ne 'print quotemeta'
              \_ Er, no. perl -ne 'print quotemeta' --scotsman
                 \_ perl -pe '$_=quotemeta'
                    -geordan
                    \_ Actually, perl -pe 's/./\Q$&/g'
                       -geordan
                       \_ That's slick, but the newline issue applies there.
                          --scotsman
                          \_ I guess
                                perl -pe 's/./\Q$&/gs'
                             would fix that, but it's still just getting
                             escaped. -geordan
           \_ This doesn't work if any of the files have newlines in their
              names.  --dbushong
              \_ Well, it escapes it, just as yours does. --scotsman