Sponsored Content
Full Discussion: Extracting filename
Top Forums UNIX for Beginners Questions & Answers Extracting filename Post 303044141 by Danette on Saturday 15th of February 2020 09:29:59 AM
Old 02-15-2020
Extracting filename

I am using bash and have a filename with a path and extension and want to extract just the filename

Have used the following code, oflna gives the file name with extension, but now neet to remove the .texi at the end.

Code:
oflna=${flnm##*/}

oflnb=${${flnm##*/}%.*}

echo "flnm: $flnm"
echo "oflna: $oflna"
echo "oflnb: $oflnb"


Code:
flnm: /home/hagbard/chaos/resip/critical/resources/reports/tdr/Development/tdr--1.0/tx411/Ch04a--Segpi--SgExtrcn--GPhy.texi
oflna: Ch04a--Segpi--SgExtrcn--GPhy.texi
oflnb:

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

extracting only the filename without its extenstion

Hi, I have a requirement that i need to store only the filename without its extension. Can anyone please help me to do this. For Example, i have stored the filename in a varialble called fname. I need to extract all the charecters before the first occurence of the dot. If fname has value... (3 Replies)
Discussion started by: lotus123
3 Replies

2. UNIX for Dummies Questions & Answers

Extracting Filename from Fullpath

Hi, Any help on this would be very appreciated. I capture the full path & filename in a variable like (varFile=/home/user/extfile.txt). Now in my shell script I have to use only the filename part i.e. extfile.txt. How do I extract only the filename part from the variable? Thanks in... (3 Replies)
Discussion started by: njoshi
3 Replies

3. Shell Programming and Scripting

gzcat into awk and then change FILENAME and process new FILENAME

I am trying to write a script that prompts users for date and time, then process the gzip file into awk. During the ksh part of the script another file is created and needs to be processed with a different set of pattern matches then I need to combine the two in the end. I'm stuck at the part... (6 Replies)
Discussion started by: timj123
6 Replies

4. Shell Programming and Scripting

Extracting the Filename

Hi, I need to extract the file name without filetype. Suppose in DIR1 if i have files like F1.txt and F2.DOC then i need to return F1 and F2 only with out file types (txt and DOC). I tried with the following code newname = ` $i | cut -d "'." -f1` but it is giving the error " 0403-006... (1 Reply)
Discussion started by: Raamc
1 Replies

5. UNIX for Dummies Questions & Answers

extracting date from a filename

Hi, I am a beginner in Unix so please bear with me... I have a directory which has files in format: RECF-YYYY-MM-DD-input. For example, RECF-2008-02-25-input. I need to extract the YYYYY-MM-DD substring from this filename and convert that into date and compare it with a date. How do I do that?... (7 Replies)
Discussion started by: laiko
7 Replies

6. Shell Programming and Scripting

Filename from splitting files to have the same filename of the original file with counter value

Hi all, I have a list of xml file. I need to split the files to a different files when see the <ko> tag. The list of filename are B20090908.1100-20090908.1200_CDMA=1,NO=2,SITE=3.xml B20090908.1200-20090908.1300_CDMA=1,NO=2,SITE=3.xml B20090908.1300-20090908.1400_CDMA=1,NO=2,SITE=3.xml ... (3 Replies)
Discussion started by: natalie23
3 Replies

7. Shell Programming and Scripting

extracting multiple variables from a filename.

hi all, I'm trying to automate some tasks and while I've got the script itself working, I'm having difficulties with automatic file detection and associated variable setting... for example, in a directory I've got several files... something along the lines of: xis0_NAME_src.file... (2 Replies)
Discussion started by: u5j84
2 Replies

8. UNIX for Dummies Questions & Answers

to extract all the part of the filename before a particular word in the filename

Hi All, Thanks in Advance I am working on a shell script. I need some assistance. My Requirement: 1) There are some set of files in a directory like given below OTP_UFSC_20120530000000_acc.csv OTP_UFSC_20120530000000_faf.csv OTP_UFSC_20120530000000_prom.csv... (0 Replies)
Discussion started by: aealexanderraj
0 Replies

9. Programming

to extract all the part of the filename before a particular word in the filename

Hi All, Thanks in Advance I am working on a shell script. I need some assistance. My code: if then set "subscriber" "promplan" "mapping" "dedicatedaccount" "faflistSub" "faflistAcc" "accumulator"\ "pam_account"; for i in 1 2 3 4 5 6 7 8;... (0 Replies)
Discussion started by: aealexanderraj
0 Replies

10. Shell Programming and Scripting

Extracting a portion of the filename

Hi I would like to extract the first portion of filename from a list of files. The filename pattern is of the form 123456789_TEXT_TEXT_TEXT_.csv. I want to extract just the numerical portion of this filename from the list of files and then output this into another text file. K (6 Replies)
Discussion started by: kamal_p_99
6 Replies
CPAN::DistnameInfo(3pm) 				User Contributed Perl Documentation				   CPAN::DistnameInfo(3pm)

NAME
CPAN::DistnameInfo - Extract distribution name and version from a distribution filename SYNOPSIS
my $pathname = "authors/id/G/GB/GBARR/CPAN-DistnameInfo-0.02.tar.gz"; my $d = CPAN::DistnameInfo->new($pathname); my $dist = $d->dist; # "CPAN-DistnameInfo" my $version = $d->version; # "0.02" my $maturity = $d->maturity; # "released" my $filename = $d->filename; # "CPAN-DistnameInfo-0.02.tar.gz" my $cpanid = $d->cpanid; # "GBARR" my $distvname = $d->distvname; # "CPAN-DistnameInfo-0.02" my $extension = $d->extension; # "tar.gz" my $pathname = $d->pathname; # "authors/id/G/GB/GBARR/..." my %prop = $d->properties; DESCRIPTION
Many online services that are centered around CPAN attempt to associate multiple uploads by extracting a distribution name from the filename of the upload. For most distributions this is easy as they have used ExtUtils::MakeMaker or Module::Build to create the distribution, which results in a uniform name. But sadly not all uploads are created in this way. "CPAN::DistnameInfo" uses heuristics that have been learnt by <http://search.cpan.org/> to extract the distribution name and version from filenames and also report if the version is to be treated as a developer release The constructor takes a single pathname, returning an object with the following methods cpanid If the path given looked like a CPAN authors directory path, then this will be the the CPAN id of the author. dist The name of the distribution distvname The file name with any suffix and leading directory names removed filename If the path given looked like a CPAN authors directory path, then this will be the path to the file relative to the detected CPAN author directory. Otherwise it is the path that was passed in. maturity The maturity of the distribution. This will be either "released" or "developer" extension The extension of the distribution, often used to denote the archive type (e.g. 'tar.gz') pathname The pathname that was passed to the constructor when creating the object. properties This will return a list of key-value pairs, suitable for assigning to a hash, for the known properties. version The extracted version AUTHOR
Graham Barr <gbarr@pobox.com> COPYRIGHT
Copyright (c) 2003 Graham Barr. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.10.1 2011-03-11 CPAN::DistnameInfo(3pm)
All times are GMT -4. The time now is 02:51 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy