Showing posts with label unix. Show all posts
Showing posts with label unix. Show all posts

Tuesday, October 23, 2012

PERL Remove array element

Deleting value from an array is easy if you know the element/index but if you only got the element/index value and not sure of it's location, you'll need a few more lines to do this. Here's a code snippet you can use if you need to delete an element to your array, given that you only know the element value.

---------------------
      my $index;
                foreach(0..$#array_list){
                        if ($array_list[$_] =~ /^$element_value/) {
                                $index = $_;
                        }
                }
                splice @array_list, $index, 1;

---------------------

This can used as a sub within your code and will require two arguments (@array_list --> the array where you need to delete something and $element_value --> the value you want to delete from you array)




Wednesday, November 5, 2008

zcat Shell command (UNIX / Linux)

The zcat command allows the user to view the contents of a compressed file without uncompressing that file by writng contents to the standard output. The zcat command does not rename the expanded file or remove the .Z extension.

The command expects compressed input files (i.e. .Z, .gz, or .bz2)

zcat is equivalent to: uncompress -c

Flags

-n Omits the compressed file header from the compressed file.
-V Writes the current version and compile options to standard error.


Example:

zcat file_1.Z wc -l (print the newline counts)

zcat file_1.Z more (filter for paging through text one screenful at a time)

Wednesday, October 29, 2008

KORN shell command line auto-complete

Add the following to the to file that your shell uses for initialization (i.e. .profile)


set -o vi



To use the command line auto complete, press Esc

Note: This only auto-complete the unique part of the file name.