Using Raku (formerly known as Perl_6)
raku -ne '.split(/ <[/=]> /).[2,4,7].put;'
Sample Input:
/logs/tc0001/tomcat/tomcat7.1/conf/catalina.properties:app.env.server.name = demo.example.com
/logs/tc0001/tomcat/tomcat7.2/conf/catalina.properties:app.env.server.name = quest.example.com
/logs/tc0001/tomcat/tomcat7.5/conf/catalina.properties:app.env.server.name = www.example.com
Sample Output:
tc0001 tomcat7.1 demo.example.com
tc0001 tomcat7.2 quest.example.com
tc0001 tomcat7.5 www.example.com
Above is a solution coded in Raku, a member of the Perl-family of programming languages. Briefly, input in read linewise with the -ne
(linewise, non-autoprinting) commandline flags. Lines are split
on a regex which consists of a custom character class (/=
) created with the <[
]>
operator. Elements [2,4,7]
are then put
to give the results above.
Of course, the above is a 'bare-bones' implementation, and Raku being a Perl-family language, TMTOWTDI applies. So lines can be split
on literal characters separated by a |
"OR" operator. Element numbering (which is zero-indexed in both Perl and Raku) can be tightened up adding the :skip-empty
adverb to the split
routine. Whitespace can be trim
-med away from each element (using map
), and the desired elements (now [1,3,6]
) are join
-ed with \t
tabs, giving the following result:
raku -ne '.split(/ "/" | "=" /, :skip-empty).map(*.trim).[1,3,6].join("\t").put;' file
tc0001 tomcat7.1 demo.example.com
tc0001 tomcat7.2 quest.example.com
tc0001 tomcat7.5 www.example.com
https://raku.org