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

2005/1/4-5 [Computer/SW/Unix] UID:35545 Activity:moderate Edit_by:auto
1/4     Hello UNIX command line gurus, let's say I have a file called
        filenames.log that contains file names, like /usr/bin/hello,
        /media/dvd/wayne's world, /media/music/my music!.mpg. I'd like
        to do something like:
        % cat filenames.log | xargs tar rvf /backup/today.tar
        However, I can't do that because I need to escape characters
        like ', \ , \!, and many others. What's an elegant way of
        doing this? I thought about using sed, but I'd have to come
        up with a comprehensive list of characters that I have to
        escape, which is lame. Ideally I'd like something like:
        % cat filenames.log | escape | xargs rvf /backup/today.tar
        Got ideas? Thanks!
        \_ Here are a few ways to do it.  Hopefully you find one elegant.
           sed 's/[^A-Za-z0-9]/\\&/g' filenames.log | xargs tar rvf ...
           sed 's/./\\&/g' filenames.log | xargs tar rvf ...
           tr '\n' '\0' <filenames.log | xargs -0 tar rvf ...
           sed 's/[^A-Za-z0-9]/\\&/g' filenames.log | xargs tar rvf today.tar
           \_ thanks. So the above sed, with "&", is equivalent to
              perl's $1 or \1? It's seems like it's the same as perl's
              s/([^A-Za-z0-9])/\\$1/g;
              So here is another question. How do you specify $1, $2,
              etc in sed? thanks.
              \_ Sed's & is perl's $& (the entire search string).  Sed uses \1,
                 \2, etc. to retrieve stuff from parens.  Also note that you
                 have to use \( and \) in sed, not just ( and ) like in perl.
           sed 's/./\\&/g' filenames.log | xargs tar rvf today.tar
           tr '\n' '\0' <filenames.log | xargs -0 tar rvf today.tar
           tar rvfI today.tar filenames.log
        \_ % cat filenames.log | perl -ne 'print quotemeta;' |
             xargs rvf /backup/today.tar
             \-i'd use the tr command above to NULL pad + xargs -0 OR
               modify a perl script called "findtar" OR use GNU tar's
               -T|--files-from option possibly with --null. ok tnx --psb
             \_ if performance is an issue would perl be slower because the
                executable is bigger? Or would it be faster because it's
                got optimizations built in?
                \-no offense, but this is not a question worth asking.
                  or at least not worth answering.
        \_ xargs is wrong in this case. Use normal tar with -T. -vadim
           \- tar -rv -f mybackup.tar -T file_list.txt
        \_ keywords: perl escape character space
ERROR, url_link recursive (eces.Colorado.EDU/secure/mindterm2) 2025/05/24 [General] UID:1000 Activity:popular
5/24    

You may also be interested in these entries...
2012/8/29-11/7 [Computer/SW/Security] UID:54467 Activity:nil
8/29    There was once a CSUA web page which runs an SSH client for logging
        on to soda.  Does that page still exist?  Can someone remind me of the
        URL please?  Thx.
        \_ what do you mean? instruction on how to ssh into soda?
           \_ No I think he means the ssh applet, which, iirc, was an applet
              that implemented an ssh v1 client.  I think this page went away
	...
2012/3/29-6/4 [Computer/HW/Memory, Computer/HW/CPU, Computer/HW/Drives] UID:54351 Activity:nil
3/29    A friend wants a PC (no mac). She doesn't want Dell. Is there a
        good place that can custom build for you (SSD, large RAM, cheap video
        card--no game)?
        \_ As a side note: back in my Cal days more than two decades ago when
           having a 387SX made me the only person with floating-point hardware,
           most machines were custom built.
	...
2012/1/27-3/26 [Computer/SW/Unix] UID:54299 Activity:nil
1/27    Interesting list of useful unix tools. Shout out to
        cowsay even!
        http://www.stumbleupon.com/su/3428AB/kkovacs.eu/cool-but-obscure-unix-tools
        \_ This is nice.  Thanks.
	...
2011/10/26-12/6 [Computer/SW/Unix] UID:54202 Activity:nil
10/24  What's an easy way to see if say column 3 of a file matches a list of
       expressions in a file? Basically I want to combine "grep -f <file>"
       to store the patterns and awk's $3 ~ /(AAA|BBB|CCC)/ ... I realize
       I can do this with "egrep -f " and use regexp instead of strings, but
       was wondering if there was some magic way to do this.
       \_ UNIX has no magic. Make a shell script to produce the ask or egrep
	...
2010/3/10-30 [Computer/SW/Mail] UID:53751 Activity:nil
3/10    What email program do people in Cal CS use nowadays?  In my school days
        people used /usr/bin/mail, then RMail in emacs, then VMail in emacs.
        After my days people used Elm, Pine, Mutt (I forgot which order).  In
        my first two jobs we could tell the seniority of fellow engineers based
        on which email program they use at work, because everyone used what
        they used to use in their school years.  In my last two jobs though,
	...
2009/11/13-30 [Computer/SW/Unix] UID:53523 Activity:nil
11/12   How does one find out if a system has rootkit installed?
        \_ Unix or m$?
           \_ Unix. On M$ I always assume it's compromised.
              \_ Install Tripwire before you plug your server into The Net?
                 The only other answer I can think of is to reinstall the
                 OS from scratch on another server and do an md checksum
	...
2009/9/4-12 [Computer/SW/OS/FreeBSD] UID:53331 Activity:kinda low
9/4     I'm seriously very happy Soda no longer runs FreeBSD.
        FreeBSD is really going down the tubes
        http://freebsdgirl.com/2009/08/its-a-dirty-job-but-someone-ha.html
        \_ funny, I dont remember it geting pwned anywhere near as many tmies
           as it has since the switch to Linux.  And that blog post is
           only abou the installer, not the running OS
	...
2009/7/24-29 [Computer/SW/Editors/Vi] UID:53195 Activity:low
7/24    Is dos2unix available somewhere?  Someone added all those Ctrl-M's to
        motd.public.
        \_ %s/^V^M//g in vim. What has your editor done for you today?
           \_ that works great in vi actually... in vim :set filetype=unix
	...