Sponsored Content
Top Forums Shell Programming and Scripting [BASH] Getting a filename its extension Post 302943241 by neutronscott on Wednesday 6th of May 2015 03:59:15 PM
Old 05-06-2015
Code:
ext=${1##*.}
if [ "$ext" = "$1" ]; then
  echo ""
else
  echo "$ext"
fi

This User Gave Thanks to neutronscott For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

separating filename and extension

Hi (warning: newbie question), I am writing a script to run a series of tests on a program, which involves a line: for file in `ls test_suite/*.args` but later I want to send the output to file.out. But I need to separate the filename and extension somehow...Also $file contains... (2 Replies)
Discussion started by: lucaspewkas
2 Replies

2. Shell Programming and Scripting

changing filename extension

Hi All, i need to change the filename extension. For simplicity, we can assume that the extension after '.' is 3 characters only... but the filenames can vary. eg. changing from abc.doc to abc.dxs can i have a oneline command to achieve this (3 Replies)
Discussion started by: Hiso
3 Replies

3. UNIX for Dummies Questions & Answers

script takes the whole filename instead of just extension

I am running my script from "/abc/" this path and it has no ".csv files" but has a ".txt" files namely temp1.txt My script goes as below, wherein it is suppose to find files with *.txt extension and *.csv extension in another path namely "/abc/xyz/": #!/bin/ksh PATH1="/abc/xyz/" value="*.csv... (1 Reply)
Discussion started by: wolverine999
1 Replies

4. Shell Programming and Scripting

cut filename extension

I need a small script (sh) to remove in a variable the filename extension. Example: f = "testfile.txt" and I need a $a with "testfile". Some one a idea? (4 Replies)
Discussion started by: Essbaumer
4 Replies

5. Shell Programming and Scripting

Getting filename with entire path without extension

Hi Experts, need one help.. m writing a shell script for which i need the entire path of the file but without its extension. running the below script gives error at the statement DIR = `dirname $FILE` --command not found. #!/bin/bash jar xvf *jar for FILE in `find . -name "*.class"` ... (3 Replies)
Discussion started by: amicableperson
3 Replies

6. Shell Programming and Scripting

removing the filename extension

Is there an easy way to strip off a filename's extension? For example, here's a filename: blahblahblah.thisisok.thisisnotok I want to get rid of .thisisnotok from the filename, so that what's left is blahblahblah.thisisok Thanks. I have a directory full of filenames that need to be... (5 Replies)
Discussion started by: daflore
5 Replies

7. Shell Programming and Scripting

Script to add extension to filename

Hi all, I have a folder with a bunch of files in them, and I would like to add an extension (.mp3)to all these filenames. The folder has only files that I'd like .mp3 added to. It looks something like this: Intput: File1 File2 File3Output: File1.mp3 File2.mp3 File3.mp3Thanks in... (2 Replies)
Discussion started by: repiv
2 Replies

8. Shell Programming and Scripting

Rename all files (filename with spaces) to different extension

Hi, I have files with filenames as below. SGM Daily Sales Email-en-us-05312012.xlwa I want to rename it in .xls. I am writing a script to change this, as there can be multiple files in subfolders. I have the following script. #!/bin/ksh for oldfile in $(find... (1 Reply)
Discussion started by: mac4rfree
1 Replies

9. UNIX for Dummies Questions & Answers

BASH - Removing the very last character(s) extension of a filename

Hello. I would like to know how to do this in bash script : A_WORD="ABCD_EFGH.0.100.40.123" NEW_WORD=remove_last_ext("A_WORD") NEW_WORD --> ABCD_EFGH.0.100.40 A_WORD="ABCD_EFGH.0.50.3" NEW_WORD=remove_last_ext("A_WORD") NEW_WORD --> ABCD_EFGH.0.50 A_WORD="ABCD_EFGH.3.100.50." ... (2 Replies)
Discussion started by: jcdole
2 Replies

10. Shell Programming and Scripting

Get latest filename without extension

I need to write a shell script to display the output of ls command like this ls -ltr *txt I get this -rw-r----- 1 oracle dba 51912704 Dec 11 10:27 /usr/local/sam/test12112012101247AM.txt -rw-r--r-- 1 oracle dba 7 Dec 11 11:58 /usr/local/sam/test.txt but I just need the latest... (7 Replies)
Discussion started by: sumang24
7 Replies
CREATE 
EXTENSION(7) PostgreSQL 9.2.7 Documentation CREATE EXTENSION(7) NAME
CREATE_EXTENSION - install an extension SYNOPSIS
CREATE EXTENSION [ IF NOT EXISTS ] extension_name [ WITH ] [ SCHEMA schema_name ] [ VERSION version ] [ FROM old_version ] DESCRIPTION
CREATE EXTENSION loads a new extension into the current database. There must not be an extension of the same name already loaded. Loading an extension essentially amounts to running the extension's script file. The script will typically create new SQL objects such as functions, data types, operators and index support methods. CREATE EXTENSION additionally records the identities of all the created objects, so that they can be dropped again if DROP EXTENSION is issued. Loading an extension requires the same privileges that would be required to create its component objects. For most extensions this means superuser or database owner privileges are needed. The user who runs CREATE EXTENSION becomes the owner of the extension for purposes of later privilege checks, as well as the owner of any objects created by the extension's script. PARAMETERS
IF NOT EXISTS Do not throw an error if an extension with the same name already exists. A notice is issued in this case. Note that there is no guarantee that the existing extension is anything like the one that would have been created from the currently-available script file. extension_name The name of the extension to be installed. PostgreSQL will create the extension using details from the file SHAREDIR/extension/extension_name.control. schema_name The name of the schema in which to install the extension's objects, given that the extension allows its contents to be relocated. The named schema must already exist. If not specified, and the extension's control file does not specify a schema either, the current default object creation schema is used. Remember that the extension itself is not considered to be within any schema: extensions have unqualified names that must be unique database-wide. But objects belonging to the extension can be within schemas. version The version of the extension to install. This can be written as either an identifier or a string literal. The default version is whatever is specified in the extension's control file. old_version FROM old_version must be specified when, and only when, you are attempting to install an extension that replaces an "old style" module that is just a collection of objects not packaged into an extension. This option causes CREATE EXTENSION to run an alternative installation script that absorbs the existing objects into the extension, instead of creating new objects. Be careful that SCHEMA specifies the schema containing these pre-existing objects. The value to use for old_version is determined by the extension's author, and might vary if there is more than one version of the old-style module that can be upgraded into an extension. For the standard additional modules supplied with pre-9.1 PostgreSQL, use unpackaged for old_version when updating a module to extension style. NOTES
Before you can use CREATE EXTENSION to load an extension into a database, the extension's supporting files must be installed. Information about installing the extensions supplied with PostgreSQL can be found in Additional Supplied Modules. The extensions currently available for loading can be identified from the pg_available_extensions or pg_available_extension_versions system views. For information about writing new extensions, see Section 35.15, "Packaging Related Objects into an Extension", in the documentation. EXAMPLES
Install the hstore extension into the current database: CREATE EXTENSION hstore; Update a pre-9.1 installation of hstore into extension style: CREATE EXTENSION hstore SCHEMA public FROM unpackaged; Be careful to specify the schema in which you installed the existing hstore objects. COMPATIBILITY
CREATE EXTENSION is a PostgreSQL extension. SEE ALSO
ALTER EXTENSION (ALTER_EXTENSION(7)), DROP EXTENSION (DROP_EXTENSION(7)) PostgreSQL 9.2.7 2014-02-17 CREATE EXTENSION(7)
All times are GMT -4. The time now is 06:28 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy