May 9, 2011

Unix copy with regular expression

measlog0, measlog2, measlog3, measlog4, measlog5, measlog6, measlog7, measlog8, measlog9, measlog10, measlog11.

I'd like to copy these files to different directory, using "cp" command with some regular expressions:

1. cp measlog?? /tmp/testdir

2. cp measlog*[0-9] /tmp/testdir

3. cp measlog[0-90-9] /tmp/testdir

4. for fn in measlog*
do cp $fn /tmp/testdir
done

5. cp measlog[0-9] measlog[0-9][0-9] /somedir

echo cp measlog[0-9] measlog[0-9][0-9] /somedir

cp knows nothing about regular expresions (or more accurately, filename generation) so the echo will show you what cp will see.

Reference

No comments: