Reverse file perl
I read that this can also be done with sed , but I prefer this perl solution. Perl reverse - Reverse file contents with Perl. By Alvin Alexander. Last updated: June 4, Perl directories - How to work on each file in a directory. Perl regex search and replace in many files. Where is Perl looking for modules to include? Perl: How to extract lines from the middle of a text file. I just create a Perl script to print the contents of a text file in reverse order.
I named this program rcat for "reverse cat" , and I use it as a helper program with my transport command a replacement for the Linux cd command. We can use it to demonstrate the Perl "reverse array" technique. As you can see, the process to reverse a Perl array is pretty simple, and in this case, it makes for a really powerful way to reverse file contents, or more specifically, display the contents of a text file in reverse order.
As mentioned, I use it as part of my "transport" program, where I use it to reverse the file that keeps the history of directories you've visited.
As a warning, I haven't tried this Perl reverse array technique with very large files. The sequence processing is copied from the question. Improve this answer.
CasimiretHippolyte Thank you very much, fixed. I had answered " reverse only the sequence and not the header ", missing the rest for some reason. I also realize now I had forgotten to copy the last sequence's print from my code. Thank you very much for the edit. Kaz Kaz When the OP asks about Perl, I'm not sure how useful it is to illustrate an answer with another language that is, at first glance, as cryptic as Perl.
Try something as follow First I split the data by the newline character. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog. Podcast Helping communities build their own LTE networks.
0コメント