Sponsored Content
Full Discussion: Extract a part of file name
Top Forums UNIX for Dummies Questions & Answers Extract a part of file name Post 302151770 by Mark Puddephat on Monday 17th of December 2007 08:54:53 AM
Old 12-17-2007
The solutions that have been suggested will work fine, so long as the length of the filename does not vary. If it does, then you need a different solution.

One possibility is this:

f=NLL_NAM_XXXXX.XXXXXXX_1_1.txt
f1=${f%%.*} # Extracts part of name before first period (NLL_NAM_XXXXX)
f2=${f#*.} # Extracts part of name after first period (XXXXXXX_1_1_.txt)
fileName=${f1##*_}.${f2%%_*}

The generation of fileName deserves a little explanation. What I have done is split the filename into the piece before the first period and the piece after. So the first piece (f1) contains the name up to XXXXX and the second piece (f2) contains the piece from XXXXXXX on. Next I strip the part of f1 up to and including the last underscore (${f1##*_}, leaving XXXXX, concatenate with a period (.) and what is left of f2 after removing everything from the first underscore on (${f2%%_*}. The resulting string (XXXXX.XXXXXXX) is assigned to the variable fileName.

This solution will work in place of the other solutions that rely on extracting a fixed length segment of srting starting a a fixed position. The difference is that the dependence on length is eliminated. The only assumption made about the string is that there is no period before the XXXXX.XXXXXXX in the original filename.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to extract certain part of log file?

Hi there, I'm having some problem with UNIX scripting (ksh), perhaps somebody can help me out? For example: ------------ Sample content of my log file (text file): -------------------------------------- File1: .... info_1 ... info_2 ... info_3 ... File2: .... info_1 ... info_2 ...... (10 Replies)
Discussion started by: superHonda123
10 Replies

2. Shell Programming and Scripting

extract last part of string.

Hi, I have a string like this BUNDLE=/home/bob/flx/user.bun how to extract only the the last part ie, only user.bun (2 Replies)
Discussion started by: vprasads
2 Replies

3. Shell Programming and Scripting

extract part of text file

I need to extract the following lines from this text and put it in different files. From xxxx@gmail.com Thu Jun 10 21:15:46 2010 Return-Path: <xxxxx@gmail.com> X-Original-To: xxx@localhost Delivered-To:xxxx@localhost Received: from ubuntu (localhost ) by ubuntu (Postfix) with ESMTP... (11 Replies)
Discussion started by: waxo
11 Replies

4. Shell Programming and Scripting

how to extract a certain part of a line

Hi friends, I want to select and use the certain part of a line. For example I have the following line home/1245/hgdf/acsdf/myhome/afolder/H2O/endfile how can I extract the part " /myhome/afolder/H2O/endfile " thanks (6 Replies)
Discussion started by: rpf
6 Replies

5. Shell Programming and Scripting

Extract part of a string

I have a file with 100s of lines of text. I want to perform an extraction of this line: Info bpzs(pid=2652) using 1000 bits I have not been able to extract it. Should I try expr match or is there another method? This line has data both in front of and in back of it. I do not have grep -o... (5 Replies)
Discussion started by: newbie2010
5 Replies

6. Shell Programming and Scripting

Extract part of file

Hello All, I need to extract part of a file into a new file My file is Define schema xxxxxx Insert into table ( a ,b ,c ,d ) values ( 1, 2, 3, (15 Replies)
Discussion started by: nnani
15 Replies

7. Shell Programming and Scripting

Extract the part of sequences from a file

I have a text file, input.fasta contains some protein sequences. input.fasta is shown below. >P02649 MKVLWAALLVTFLAGCQAKVEQAVETEPEPELRQQTEWQSGQRWELALGRFWDYLRWVQT LSEQVQEELLSSQVTQELRALMDETMKELKAYKSELEEQLTPVAEETRARLSKELQAAQA RLGADMEDVCGRLVQYRGEVQAMLGQSTEELRVRLASHLRKLRKRLLRDADDLQKRLAVY... (8 Replies)
Discussion started by: rahim42
8 Replies

8. UNIX for Advanced & Expert Users

Need help to extract part of the string

Hi, I have a string with name as 20140412-s1-Potopolive_promos_20140412. So I want to extract only Potopolive string. Could you please help me the command. O/p : Potopolive Thx in advance (5 Replies)
Discussion started by: lkeswar
5 Replies

9. Programming

Extract part of an archive to a different file

I need to save part of a file to a different one, start and end offset bytes are provided by two counters in long format. If the difference is big, how should I do it to prevent buffer overflow in java? (7 Replies)
Discussion started by: Tribe
7 Replies

10. Shell Programming and Scripting

Extract a part of variable/line content in a file

I have a variable and assigned the following values ***XYZ_201519_20150929140642_20150929140644_211_0_0_211 I need to read this variable from backward and stop read when I get first underscore (_) In this scenario I should get 211 Thanks Kris (3 Replies)
Discussion started by: mkris
3 Replies
DateTime::Locale::ar_LB(3)				User Contributed Perl Documentation				DateTime::Locale::ar_LB(3)

NAME
DateTime::Locale::ar_LB SYNOPSIS
use DateTime; my $dt = DateTime->now( locale => 'ar_LB' ); print $dt->month_name(); DESCRIPTION
This is the DateTime locale package for Arabic Lebanon. DATA
This locale inherits from the DateTime::Locale::ar locale. It contains the following data. Days Wide (format) XXXXXXX XXXXXXXX XXXXXXXX XXXXXX XXXXXX XXXXX XXXXX Abbreviated (format) XXXXXXX XXXXXXXX XXXXXXXX XXXXXX XXXXXX XXXXX XXXXX Narrow (format) XXXXXXX XXXXXXXX XXXXXXXX XXXXXX XXXXXX XXXXX XXXXX Wide (stand-alone) XXXXXXX XXXXXXXX XXXXXXXX XXXXXX XXXXXX XXXXX XXXXX Abbreviated (stand-alone) XXXXXXX XXXXXXXX XXXXXXXX XXXXXX XXXXXX XXXXX XXXXX Narrow (stand-alone) X X X X X X X Months Wide (format) XXXXX XXXXXX XXXX XXXX XXXXX XXXX XXXXXX XXXX XX XXXXX XXXXX XXXXX XXXXX XXXXXX XXXXX XXXXX Abbreviated (format) XXXXX XXXXXX XXXX XXXX XXXXX XXXX XXXXXX XXXX XX XXXXX XXXXX XXXXX XXXXX XXXXXX XXXXX XXXXX Narrow (format) XXXXX XXXXXX XXXX XXXX XXXXX XXXX XXXXXX XXXX XX XXXXX XXXXX XXXXX XXXXX XXXXXX XXXXX XXXXX Wide (stand-alone) XXXXX XXXXXX XXXX XXXX XXXXX XXXX XXXXXX XXXX XX XXXXX XXXXX XXXXX XXXXX XXXXXX XXXXX XXXXX Abbreviated (stand-alone) XXXXX XXXXXX XXXX XXXX XXXXX XXXX XXXXXX XXXX XX XXXXX XXXXX XXXXX XXXXX XXXXXX XXXXX XXXXX Narrow (stand-alone) X X X X X X X X X X X X Quarters Wide (format) XXXXX XXXXX XXXXX XXXXXX XXXXX XXXXXX XXXXX XXXXXX Abbreviated (format) XXXXX XXXXX XXXXX XXXXXX XXXXX XXXXXX XXXXX XXXXXX Narrow (format) X X X X Wide (stand-alone) XXXXX XXXXX XXXXX XXXXXX XXXXX XXXXXX XXXXX XXXXXX Abbreviated (stand-alone) XXXXX XXXXX XXXXX XXXXXX XXXXX XXXXXX XXXXX XXXXXX Narrow (stand-alone) X X X X Eras Wide XXX XXXXXXX XXXXXX Abbreviated X.X X Narrow X.X X Date Formats Full 2008-02-05T18:30:30 = XXXXXXXXX 5 XXXXX 2008 1995-12-22T09:05:02 = XXXXXXX 22 XXXXX XXXXXX 1995 -0010-09-15T04:44:23 = XXXXXX 15 XXXXXX -10 Long 2008-02-05T18:30:30 = 5 XXXXX 2008 1995-12-22T09:05:02 = 22 XXXXX XXXXXX 1995 -0010-09-15T04:44:23 = 15 XXXXXX -10 Medium 2008-02-05T18:30:30 = 05X/02X/2008 1995-12-22T09:05:02 = 22X/12X/1995 -0010-09-15T04:44:23 = 15X/09X/-010 Short 2008-02-05T18:30:30 = 5X/2X/2008 1995-12-22T09:05:02 = 22X/12X/1995 -0010-09-15T04:44:23 = 15X/9X/-010 Default 2008-02-05T18:30:30 = 05X/02X/2008 1995-12-22T09:05:02 = 22X/12X/1995 -0010-09-15T04:44:23 = 15X/09X/-010 Time Formats Full 2008-02-05T18:30:30 = UTC 6:30:30 X 1995-12-22T09:05:02 = UTC 9:05:02 X -0010-09-15T04:44:23 = UTC 4:44:23 X Long 2008-02-05T18:30:30 = UTC 6:30:30 X 1995-12-22T09:05:02 = UTC 9:05:02 X -0010-09-15T04:44:23 = UTC 4:44:23 X Medium 2008-02-05T18:30:30 = 6:30:30 X 1995-12-22T09:05:02 = 9:05:02 X -0010-09-15T04:44:23 = 4:44:23 X Short 2008-02-05T18:30:30 = 6:30 X 1995-12-22T09:05:02 = 9:05 X -0010-09-15T04:44:23 = 4:44 X Default 2008-02-05T18:30:30 = 6:30:30 X 1995-12-22T09:05:02 = 9:05:02 X -0010-09-15T04:44:23 = 4:44:23 X Datetime Formats Full 2008-02-05T18:30:30 = XXXXXXXXX 5 XXXXX 2008 UTC 6:30:30 X 1995-12-22T09:05:02 = XXXXXXX 22 XXXXX XXXXXX 1995 UTC 9:05:02 X -0010-09-15T04:44:23 = XXXXXX 15 XXXXXX -10 UTC 4:44:23 X Long 2008-02-05T18:30:30 = 5 XXXXX 2008 UTC 6:30:30 X 1995-12-22T09:05:02 = 22 XXXXX XXXXXX 1995 UTC 9:05:02 X -0010-09-15T04:44:23 = 15 XXXXXX -10 UTC 4:44:23 X Medium 2008-02-05T18:30:30 = 05X/02X/2008 6:30:30 X 1995-12-22T09:05:02 = 22X/12X/1995 9:05:02 X -0010-09-15T04:44:23 = 15X/09X/-010 4:44:23 X Short 2008-02-05T18:30:30 = 5X/2X/2008 6:30 X 1995-12-22T09:05:02 = 22X/12X/1995 9:05 X -0010-09-15T04:44:23 = 15X/9X/-010 4:44 X Default 2008-02-05T18:30:30 = 05X/02X/2008 6:30:30 X 1995-12-22T09:05:02 = 22X/12X/1995 9:05:02 X -0010-09-15T04:44:23 = 15X/09X/-010 4:44:23 X Available Formats d (d) 2008-02-05T18:30:30 = 5 1995-12-22T09:05:02 = 22 -0010-09-15T04:44:23 = 15 EEEd (d EEE) 2008-02-05T18:30:30 = 5 XXXXXXXX 1995-12-22T09:05:02 = 22 XXXXXX -0010-09-15T04:44:23 = 15 XXXXX Hm (H:mm) 2008-02-05T18:30:30 = 18:30 1995-12-22T09:05:02 = 9:05 -0010-09-15T04:44:23 = 4:44 hm (h:mm a) 2008-02-05T18:30:30 = 6:30 X 1995-12-22T09:05:02 = 9:05 X -0010-09-15T04:44:23 = 4:44 X Hms (H:mm:ss) 2008-02-05T18:30:30 = 18:30:30 1995-12-22T09:05:02 = 9:05:02 -0010-09-15T04:44:23 = 4:44:23 hms (h:mm:ss a) 2008-02-05T18:30:30 = 6:30:30 X 1995-12-22T09:05:02 = 9:05:02 X -0010-09-15T04:44:23 = 4:44:23 X M (L) 2008-02-05T18:30:30 = 2 1995-12-22T09:05:02 = 12 -0010-09-15T04:44:23 = 9 Md (d/XM) 2008-02-05T18:30:30 = 5/X2 1995-12-22T09:05:02 = 22/X12 -0010-09-15T04:44:23 = 15/X9 MEd (EX d-M) 2008-02-05T18:30:30 = XXXXXXXXX 5-2 1995-12-22T09:05:02 = XXXXXXX 22-12 -0010-09-15T04:44:23 = XXXXXX 15-9 MMdd (ddX/MM) 2008-02-05T18:30:30 = 05X/02 1995-12-22T09:05:02 = 22X/12 -0010-09-15T04:44:23 = 15X/09 MMM (LLL) 2008-02-05T18:30:30 = XXXX 1995-12-22T09:05:02 = XXXXX XXXXX -0010-09-15T04:44:23 = XXXXX MMMd (d MMM) 2008-02-05T18:30:30 = 5 XXXX 1995-12-22T09:05:02 = 22 XXXXX XXXXX -0010-09-15T04:44:23 = 15 XXXXX MMMEd (E d MMM) 2008-02-05T18:30:30 = XXXXXXXX 5 XXXX 1995-12-22T09:05:02 = XXXXXX 22 XXXXX XXXXX -0010-09-15T04:44:23 = XXXXX 15 XXXXX MMMMd (d MMMM) 2008-02-05T18:30:30 = 5 XXXX 1995-12-22T09:05:02 = 22 XXXXX XXXXX -0010-09-15T04:44:23 = 15 XXXXX MMMMEd (E d MMMM) 2008-02-05T18:30:30 = XXXXXXXX 5 XXXX 1995-12-22T09:05:02 = XXXXXX 22 XXXXX XXXXX -0010-09-15T04:44:23 = XXXXX 15 XXXXX ms (mm:ss) 2008-02-05T18:30:30 = 30:30 1995-12-22T09:05:02 = 05:02 -0010-09-15T04:44:23 = 44:23 y (y) 2008-02-05T18:30:30 = 2008 1995-12-22T09:05:02 = 1995 -0010-09-15T04:44:23 = -10 yM (MX/yyyy) 2008-02-05T18:30:30 = 2X/2008 1995-12-22T09:05:02 = 12X/1995 -0010-09-15T04:44:23 = 9X/-010 yMEd (EEEX d/XM/Xyyyy) 2008-02-05T18:30:30 = XXXXXXXXX 5/X2/X2008 1995-12-22T09:05:02 = XXXXXXX 22/X12/X1995 -0010-09-15T04:44:23 = XXXXXX 15/X9/X-010 yMMM (MMM y) 2008-02-05T18:30:30 = XXXX 2008 1995-12-22T09:05:02 = XXXXX XXXXX 1995 -0010-09-15T04:44:23 = XXXXX -10 yMMMEd (EEEX d MMMM y) 2008-02-05T18:30:30 = XXXXXXXXX 5 XXXX 2008 1995-12-22T09:05:02 = XXXXXXX 22 XXXXX XXXXX 1995 -0010-09-15T04:44:23 = XXXXXX 15 XXXXX -10 yMMMM (MMMM y) 2008-02-05T18:30:30 = XXXX 2008 1995-12-22T09:05:02 = XXXXX XXXXX 1995 -0010-09-15T04:44:23 = XXXXX -10 yQ (yyyy Q) 2008-02-05T18:30:30 = 2008 1 1995-12-22T09:05:02 = 1995 4 -0010-09-15T04:44:23 = -010 3 yQQQ (y QQQ) 2008-02-05T18:30:30 = 2008 XXXXX XXXXX 1995-12-22T09:05:02 = 1995 XXXXX XXXXXX -0010-09-15T04:44:23 = -10 XXXXX XXXXXX yyQ (Q yy) 2008-02-05T18:30:30 = 1 08 1995-12-22T09:05:02 = 4 95 -0010-09-15T04:44:23 = 3 -10 yyyyMM (MMX/yyyy) 2008-02-05T18:30:30 = 02X/2008 1995-12-22T09:05:02 = 12X/1995 -0010-09-15T04:44:23 = 09X/-010 yyyyMMMM (MMMMX y) 2008-02-05T18:30:30 = XXXXX 2008 1995-12-22T09:05:02 = XXXXX XXXXXX 1995 -0010-09-15T04:44:23 = XXXXXX -10 Miscellaneous Prefers 24 hour time? No Local first day of the week XXXXXXX SUPPORT
See DateTime::Locale. AUTHOR
Dave Rolsky <autarch@urth.org> COPYRIGHT
Copyright (c) 2008 David Rolsky. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. This module was generated from data provided by the CLDR project, see the LICENSE.cldr in this distribution for details on the CLDR data's license. perl v5.18.2 2017-10-06 DateTime::Locale::ar_LB(3)
All times are GMT -4. The time now is 11:09 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy