Sorting and merging files

The following script merges several files into one file.

#!/bin/bash
echo "Please specify a directory"
read folder
cd $folder
ls | sort -n
for i in *.fasta
    do
    cat $i >> virus
done

Line 5 creates a sorted list of directory contents. Line six loops through all files with .fasta extension. Line 8 appends contents of every file to the file virus.

Changing file extensions

Suppose I need to change the file extensions of certain files in a directory.

#!/bin/bash
echo "Please specify a directory: "
read folder
cd $folder
for i in *.txt
    do
    mv "$i" `basename $i txt`fasta
done

The directory address specified by the user is read into the script in line 2. This address is used to cd to the directory. This script changes the extensions of .txt files to .fasta.

Displaying directory contents

For security reasons, most servers on the Internet do not show the contents of a directory if the directory address is typed. The user is either redirected to index.whatever, a default page, page not found or access denied. Thus the list of files in the directory are not displayed.

If you need to show the contents of your directory, you can use the following code:

Listing tables, views, procedures, indices, packages, sequences, synonyms, triggers in Oracle

If you want to list tables in MySQL, you simply type the following command:

show tables

Oracle does not provide such a short cut. You have to type the following command:

select * from user_objects where object_type = 'TABLE'

The word TABLE must be uppercase. This would lisl all tables in the database. The same query could be modified slightly to list functions, procedures, sequences, view and more.

List functions

select * from user_objects where object_type = 'TABLE'

List views

Oracle NVL2 function

NVL2 function extends the funcitonality of NVL function. NVL function prints the value of the variable unless a null value is encountered; in which case a value is substituted for the null. In addition to this, NVL2 also allows you to substitute a value if the value of the variable is not null. Syntax:

NVL2(variable, not_null_substitute, null_substitute)

Example

Pages