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


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers to extract all the part of the filename before a particular word in the filename
# 1  
Old 08-27-2012
MySQL 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
OTP_UFSC_20120530000000_subs.csv

I want to check if all thes files exists in the directory

the keywords are acc.csv, faf.csv, prom.csv, subs.csv
apart from this all the other things vary time to time (like the field seperator used in the file (can be.,-,_ etc) and the names OTP UFSC will vary.

2) if the file does not exist I have to touch (Create a empty file by that name)
Example : Imagine the file OTP_UFSC_20120530000000_acc.csv doesnot exist
in the directory
I have to search first if a file *acc.csv exist in the directory or not. If not i will extract the prefix (anything before acc.csv in this case OTP_UFSC_20120530000000_) from an existing file which is common to all the files in the directory
and create a file OTP_UFSC_20120530000000_acc.csv

Smilie
Any suggestions and help

Moderator's Comments:
Mod Comment Please do not cross-post. Thanks. Closed.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Extract date and time part from filename

Hi, I am facing one scenario in which I need to extract exact position of date and time from the name of the files. For example, Below is the record in which I need to extract position of YYYYMMDD,HHMISS and YYMMDD. Date and time variables can come more than once. I need to use these position... (13 Replies)
Discussion started by: Prathmesh
13 Replies

2. Shell Programming and Scripting

Finding the part of a filename

Hi, I am writing an ebuild for Gentoo Linux operating system. Writing an ebuild is about Bash scripting where I am a newbie. So, my ebuild must find a part of a specific filename. Such a filaname my look like this: libvclient_release_x64.so.740and I must to find the number at the and of... (18 Replies)
Discussion started by: csanyipal
18 Replies

3. UNIX for Dummies Questions & Answers

Extract Date part from the filename

Hi All, I have incoming source files abcmmyy.txt I need to extract the mmyy part from the filename and pass that to a variable . I really appreciate your quick response on this. Thanks raj (7 Replies)
Discussion started by: rajeevm
7 Replies

4. UNIX for Dummies Questions & Answers

Replacing part of filename

Hi guys! I have quite a lot of files like all_10001_ct1212307460308.alf* and I want to get rid of the first number for all at once like: all_ct1212307460308.alf* How can I do this in the shell? (12 Replies)
Discussion started by: TimmyTiz
12 Replies

5. Shell Programming and Scripting

Extract a part of a filename containing a particular word

Hi All, Thanks in Advance Shell Script or Perl Script 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... (7 Replies)
Discussion started by: aealexanderraj
7 Replies

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

7. Shell Programming and Scripting

cut the some part in filename

Hi All, I have the file & name is "/a/b/c/d/e/xyz.dat" I need "/a/b/c/d/e/" from the above file name. I tryning with echo and awk. But it not come. Please help me in this regard. Thanks & Regards, Dathu (3 Replies)
Discussion started by: pdathu
3 Replies

8. Shell Programming and Scripting

Getting part of a filename

Hi All, I'm trying to get part of a filename and my skill with regular expression are lacking. I know I need to use SED but have no idea how to use it. I'm hoping that someone can help me out. The file names would be: prefix<partwewant>suffix.extension the prefix and suffix are always 3... (4 Replies)
Discussion started by: imonkey
4 Replies

9. UNIX for Dummies Questions & Answers

Strip part from filename

I've many file like this 01-file 01_-_file 01_-_file 01_-_file 01_-_file 01-file I would remove bold part from filename. Suggestions?Thanks (4 Replies)
Discussion started by: cv313x
4 Replies

10. Shell Programming and Scripting

part of a filename

Hi, I need to extract only a part of the filenames of some files. The files are named this way : .tap_profile_SIT02 I want the "SIT02" part, which is not the same for each file. I was able to get what I want with bash, but not with ksh. Here is the command I used in bash : find... (8 Replies)
Discussion started by: flame_eagle
8 Replies
Login or Register to Ask a Question