Sponsored Content
Top Forums UNIX for Beginners Questions & Answers How to extract when filename contains file seperator..? Post 303015626 by Don Cragun on Monday 9th of April 2018 06:50:24 AM
Old 04-09-2018
If you state that _ and - are word separators and you want the first 5 words from the string contained in a variable; no your code cannot reliably guess at how many separators in the first 5 words are not separators.

If you know that the part of the filename that you do not want always ends with three occurrences of _string, you could use:
Code:
File="010020004_S-TOR-Sort-CAS_P_20170519_121504_0007.TXT"
FilePart=${File%_*_*_*}
echo "$FilePart"

with any shell that performs the variable expansions required by the POSIX standards.

Note also that there is a huge difference between using the command name echo and the command name Echo in any system that conforms to the standards. Utility names are case sensitive and there is no definition in the standards as to what a command named Echo will do (if such a command exists on your system).

Also note that there is no need to use echo and command substitution in the assignment of the variable expansion.

Last edited by Don Cragun; 04-09-2018 at 07:53 AM.. Reason: Add second note.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

extract only filename

Hi, I want to display only the file names of the ls command with a delimiter of comma. For example:- ls /etc/dir/N* gives the following output /etc/dir/N1 /etc/dir/N2 /etc/dir/N3 I want the output as N1,N2,N3,-->Here i need the final comma also. Also, here /etc/dir is being... (2 Replies)
Discussion started by: dnat
2 Replies

2. Shell Programming and Scripting

Add a field seperator in a file.

"355"|""|"NJ"|"A0A 1W0"|"V"|""|""|""|"N" I've the above sample data seperated with pipe delimeter and in the file I want to replace a space with "|" to the 4th field so the result would be like below. So it would change from 9 fields to 10 fields. "355"|""|"NJ"|"A0A"|"1W0"|"V"|""|""|""|"N" ... (3 Replies)
Discussion started by: rudoraj
3 Replies

3. Shell Programming and Scripting

How to extract timestamp from the filename?

Hi., My file name is of the format: name_abc_20100531_142528.txt where., my timestamp is of the format: yyyymmdd_hhmmss How to extract the date strring and time string into seperate variables in the shell script, after reading the file as the input? I want to get the variables... (9 Replies)
Discussion started by: av_vinay
9 Replies

4. UNIX for Dummies Questions & Answers

Extract first line of a file and use as filename

I am trying to find a way to create a script which will extract the first line of a file and then rename the file (or create a new file with the same content as the old file) using the first line as the name. The first line being a single word, that is. I am hopeless at programming, if anyone can... (5 Replies)
Discussion started by: s.plumb
5 Replies

5. Shell Programming and Scripting

Extract date from filename and create a new file

Hi, i have a filename CRED20102009.txt in a server 20102009 is the date of the file ddmmaaaa format the complete route is /dprod/informatica/Fuentes/CRED20102009.csv i want to extract the date to create a new file named Parameters.txt I need to create Parameters.txt with this... (6 Replies)
Discussion started by: angel1001
6 Replies

6. Shell Programming and Scripting

extract every filename containing certain string in a directory and do some commend per file

Hi, Here is my question: suppose I have files like 1990_8xdaily_atmos.nc 1991_8xdaily_atmos.nc 1992_8xdaily_atmos.nc 1993_8xdaily_atmos.nc 1990_daily_atmos.nc 1991_daily_atmos.nc 1992_daily_atmos.nc 1993_daily_atmos.nc 1990_month_atmos.nc 1991_month_atmos.nc 1992_month_atmos.nc... (1 Reply)
Discussion started by: 1988PF
1 Replies

7. 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

8. 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

9. Shell Programming and Scripting

Extract string from filename

Hi I need to extract the string from file name filename: FILENAME_STRUT_01032013_XXXXXXX.TXT I want 01032013 from the above file name. number of characters may differ before the required string but underscores(-) are same number i.e. after second underscore. Please advise on this. ... (2 Replies)
Discussion started by: cnrj
2 Replies

10. Shell Programming and Scripting

Extract data according to keys from filename mentioned in file

Hello experts, I want to join a file with files whosE names are mentioned in one of the columns of the same file. File 1 t1,a,b,file number 1 t1,a,c,file number 1 t2,c,d,file number 2 t2,c,e,file number 2 t2,c,f,file number 2 t2,c,g,file number 2 t3,e,f,file number 3 file number 1... (3 Replies)
Discussion started by: ritakadm
3 Replies
GEXTRACTWINICONS(1)					      General Commands Manual					       GEXTRACTWINICONS(1)

NAME
gExtractWinIcons - Extract cursors and icons from MS Windows compatible resource files SYNOPSIS
gextractwinicons -h gextractwinicons [options] DESCRIPTION
gExtractWinIcons is a GTK+ utility to extract cursors, icons and png images from MS Windows compatible resource files (.exe, .dll, .ocx, .cpl and many others). To extract icons or cursors just to select a MS Windows compatible resource file and the contained resources will be shown. Select a desti- nation directory where to save the selected resources, simply check the items to extract and press the save button to save them in the specified path. OPTIONS
This program follow the usual GNU command line syntax, with long options starting with two dashes (`-'). A summary of options is included below. -h, --help Show summary of options -d, --destination Set destination folder for extracted resources -f, --filename Set resources filename from which to extract the resources -r, --refresh Automatically refresh the resources list if -f (--filename) was specified AUTHORS
gExtractWinIcons was written by Fabio Castelli <muflone@vbsimple.net>. HOMEPAGE
http://code.google.com/p/gextractwinicons/ January 3, 2010 GEXTRACTWINICONS(1)
All times are GMT -4. The time now is 08:23 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy