[lug] Newline in a filename
Tkil
tkil at scrye.com
Sun Nov 11 10:28:46 MST 2001
>>>>> "Timothy" == Timothy C Klein <teece at silverklein.net> writes:
Timothy> The question mark is the new line. When I try to delete by
Timothy> using tab expansion, the question mark turns into a newline,
Timothy> confusing things. I am not sure how to escape the new line
Timothy> character. How can I delete this guy?
the easiest way is to just use a wildcard; this is what the question
mark is hinting at, anyway:
| $ touch 'foo
| > bar'
| $ ls
| foo?bar
| $ rm foo?bar
| $ ls
| $
if you have many of them to get rid of, you could look at "find" with
the "-print0" option, feeding into "xargs" with the "-0" flag:
| $ find . -type f -name 'cp9-*' -print0 | xargs -0 rm
finally, you could just use perl again:
| $ perl -e 'unlink "foo\nbar"'
the question of quoting is something that will often get me to write
even simple scripts in perl, instead of bash or other shells: in perl,
the quoting is more powerful (and, to me, more straightforward), as
well as giving me much more precision about word or line separators.
t.
p.s. for renaming files, i wrote a perl script i called "pmv". it
accepts a regular expression as its first argument, and an
arbitrary perl expression as its second argument. this is very
handy for e.g. lowercasing a bunch of filenames:
pmv '\.JPG$' 'lc $&'
my original intent was to make multiple-part files have a uniform
number of digits (so that i wouldn't get the "p1 p10 p11 p2 p3"
effect when sorting):
pmv '(part-)(\d+)' 'sprintf "%s%02d", $1, $2'
i don't remember how well i documented it, but it is available
at:
http://slinky.scrye.com/~tkil/perl/pmv
More information about the LUG
mailing list