[nSLUG] Any Perl Experience around?

Hatem Nassrat hnassrat at gmail.com
Thu Jun 22 13:27:13 ADT 2017


On Thu, Jun 22, 2017 at 12:46 PM, Hatem Nassrat <hnassrat at gmail.com> wrote:
>
> Your problem is most likely with the column command. Also this is a long
> explanation to say my regex is solid :P
>

Here is a version of the command that works, it essentially adds 10 spaces
on lines that have colors, (counted by looking at the file in vim, without
the initial escape character, each colored line has 10 characters of color
stuff). This means that your columnar output is now 10 chars longer, so you
need to consider that in your char count inside the curly brackets inside.
Essentially none colored file names are penalized ... what can be done
there is a slightly more complex regex where the non colored lines are
allowed an extra 10 characters from their colored counterparts. Both below.

/bin/ls -Fc --color | perl -lne
's/((?:\e\[\d+(?:;\d+)?m)*)([^\e]{24})[^\e]*(.*)/$1$2...$3/s; print' |
column -x | perl -lne 's/(\e\[0m[^\t]*)(\t)/$1          $2/sg; print'

OR

# note I made the length 5 and 15 for testing, changing it to 24 and 34
should match the original github code size for the 2 col version

/bin/ls -Fc --color | perl -lne
's/(?:((?:\e\[\d+(?:;\d+)?m)+)([^\e]{5})[^\e]*(.*))|(?:(.{15}).*)/$1$2$4...$3/s;
print' | column -x | perl -lne 's/(\e\[0m[^\t]*)(\t)/$1          $2/sg;
print'

-- 
Hatem
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://nslug.ns.ca/pipermail/nslug/attachments/20170622/9c8e66c0/attachment.html>


More information about the nSLUG mailing list