May 2013
Beginner to intermediate
384 pages
7h 40m
English
Several shell scripts perform manipulations based on filenames. We may need to perform actions such as renaming the files by preserving the extension, converting files from one format to another (change the extension by preserving the name), extracting a portion of the filename, and so on. The shell comes with inbuilt features for slicing filenames based on different conditions. Let us see how to do it.
The name from name.extension can be easily extracted using the % operator. You can extract the name from "sample.jpg" as follows:
file_jpg="sample.jpg"
name=${file_jpg%.*}
echo File name is: $nameThe output is:
File name is: sample
The next task is to extract the extension of a file from its filename. ...
Read now
Unlock full access