Perl Is Still The Goddess For Text Manipulation

", split/|/, $_)'File ManipulationInsert line numbers:perl -i -ne 'printf "%04d %s", $.

, $_'Reverse lines of file abc.

txt and print it:perl -e 'print reverse <>' abc.

txtIncrement all numbers in abc.

txt by 1:perl -pe 's/(d+)/ 1 + $1 /ge' abc.

txtColumns and Rows ProcessingPrinting columns 1–5:perl -F" " -nlae'print join " ", @F[0.

4]'Printing individual columns, 1, 3, last:perl -F" " -nlae'print join " ", @F[0,2,-1]'Print selective lines numbered 12, 20, 27:perl -ne 'print if $.

==12 || $.

==20 || $.

==27'Print all lines from line 18 to line 29:perl -ne 'print if $.

>=18 && $.

<=29'Print all lines between two patterns:perl -ne 'print if (/^START/.

/^END/);'Armed with this list of powerful perl commands to clean up your data, go and be the programmer or the data scientist that you are.

.

. More details

Leave a Reply