Well, I am no expert and I certainly am still learning my one liners. However, the thing that immediately popped out at me is:
Your grep regex probably doesn't need to be so specific. According to the file you gave in your example and the fact that you were no more specific than what you gave in your example, then I would break that grep() into a really basic pattern match so that the file(s) would be picked up. This makes your one-liner a little bit shorter. However, the regex also makes the one-liner less specific if you have files that have other patterns that need to be matched.
I changed it to use map which I am quite new at but am really growing to like. Thing is I think that the regex portion of my dealy here can be improved upon but I couldn't fix it quick enough before I had to get back to work.
perl -e 'map{($a=$_)=~s/REPT/ERR/,rename($_,$a)}glob("*.REPT")'
Yours first one liner was about 83 characters (minus a few because I had to escape some of the special characters...)
perl -e '$var = "\@m=glob(\"*\");\@m = grep{m/\d+_\d+\.REPT/g} \@m; fo
+reach(\@m){$s=$_;$s=~s/REPT/ERR/; rename($_,$s);}";print length($var)
+,"\n";'
83
Mine has 45 (same with mine..minus a couple characters since Im not sure if Perl counted the escapes)
perl -e '$var = "map{($a=$_)=~s/REPT/ERR/,rename($_,$a)}glob(\"*.REPT\
+")";print length($var),"\n";'
45
[qadmin@concon qw]$ ls -1 *REPT *ERR
ls: *ERR: No such file or directory
353513_3.REPT
42342_12.REPT
442342_2.REPT
[qadmin@concon qw]$ perl -e 'map{($a=$_)=~s/REPT/ERR/,rename($_,$a)}gl
+ob("*.REPT")'
[qadmin@concon qw]$ ls -1 *REPT *ERR
ls: *REPT: No such file or directory
353513_3.ERR
42342_12.ERR
442342_2.ERR
[qadmin@concon qw]$
----------
- Jim
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.