reverse

Linux find command - reverse the meaning of a file search

Summary: How to reverse the meaning of a Linux find command.

I spent last night doing a bunch of work on my source code warehouse. At the end of the night I needed to do a search for all files in many subdirectories whose filenames did not end with "*.java". It's easy enough to find filenames that do end with "*.java", using the find command like this:

A Perl reverse array example

Perl reverse array FAQ: How do I reverse the contents of an array in Perl? (or, How do I use the Perl reverse function?)

It turns out that it's easy to reverse a Perl array, especially if you have already defined the sorting/comparing algorithm that Perl needs to sort the array.

A Perl reverse array example

For example, if you just want to reverse the lines in a Perl array that you've read from a text file, you can just use this Perl script:

grep reverse - how to reverse the meaning of a grep search

Problem

You need to reverse the meaning of a search you're performing with the grep command. For instance, you've been searching for pepperoni pizza orders like this:

grep pepperoni pizza-orders.txt

and now you need to find all orders that don't have pepperoni.

Solution

Just add the -v switch to your grep search command, like this:

Perl sort array example - How to sort a Perl string array

Summary: How to sort a Perl string array (when you don't have to worry about whether the strings are all uppercase or lowercase).

Perl excels at a number of tasks, especially text-processing, and if you have an array of strings, and all of the elements in the array are either uppercase or lowercase, sorting your string array is very easy. In this tutorial I'll show how to sort an array of strings, and will also show how to sort your string array in reverse order.

Perl reverse - Reverse file contents with Perl

Working on a Unix system, I just needed to reverse the contents of a file, and thought I'd show how I ended up doing it.

My file-reversal needs

For my situation I needed to (a) get 10 lines from the end of a file, (b) reverse those ten lines, and (c) save them to another file. If my Unix system supported the -r option of the tail command this would have been a no-brainer, but it didn't, so I had to work a little harder.

A Perl reverse lines tip

Perl rules! Yesterday I needed a program that would print a file in reverse, i.e., last line first, first line last. Before I could fret "man, how am I going to do this?", a powerful two-line program spewed forth:

@lines = <>;
print reverse @lines;

Life is good.

Syndicate content