parse file names


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting parse file names
# 1  
Old 03-28-2011
parse file names

trying to parse out all parts of this file name.

Code:
REC=`echo "CAMXI.F0150.txt" | sed 's/.*[FfVv]\([0-9][0-9][0-9][0-9][^.]*\)[.].*/\1/'`
export "FLRECL=$REC"
FLECL=0150

I can get the numbers 0150 out of the file name. But need to capture first 5 bytes and extension. So i would export 3 variables (name, length, extension) ignore everything else

thanks for your help.

Last edited by radoulov; 03-28-2011 at 05:51 PM.. Reason: added code tags
# 2  
Old 03-28-2011
Code:
echo "CAMXI.F0150.txt" |grep -o '[A-Z]*\.[A-Z]'
CAMXI.F
echo "CAMXI.F0150.txt" |grep -o '[0-9]\{4\}'
0150
echo "CAMXI.F0150.txt" |grep -o '\.[a-z].*'
.txt

# 3  
Old 03-28-2011
thanks. i can't use grep -o. only -hblcnsviw.

all of which return nothing or the entire file name.CAMXI.F0150.txt
CAMXI.F0150.txt
CAMXI.F0150.txt
# 4  
Old 03-28-2011
another way:

Code:
 var=CAMXI.F0150.txt
 
echo ${var##*[0-9]}
.txt
 echo ${var%%[0-9]*}
CAMXI.F

echo ${var%\.*}|tr -d '[A-Z.]'
0150

# 5  
Old 03-28-2011
appreciate it.

.txt
CAMXI.F
CMXIF0150
# 6  
Old 03-28-2011
Code:
echo ${var%\.*}|tr -d '.A'
CMXIF0150

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

I have strigns below, in which we have files names. Can we parse them in one algorithm? If not, the

I have several strings with files names roundrobin_report_report_ALL_dbagadm_${Today}-${TM}_U.csv I want to say That I found a way to have prefix roundrobin_report_report_ALL_dbagadmU. letter=`echo $var | cut -d'.' -f 1 | rev | cut -d'_' -f 1 | rev` echo "NAME = $letter" prefix=`echo $var... (1 Reply)
Discussion started by: digioleg54
1 Replies

2. Shell Programming and Scripting

Exclude certain file names while selectingData files coming in different names in a file name called

Data files coming in different names in a file name called process.txt. 1. shipments_yyyymmdd.gz 2 Order_yyyymmdd.gz 3. Invoice_yyyymmdd.gz 4. globalorder_yyyymmdd.gz The process needs to discard all the below files and only process two of the 4 file names available ... (1 Reply)
Discussion started by: dsravanam
1 Replies

3. Shell Programming and Scripting

Change the file name and copy old file content to new file names.

Hi, I have a files in a directory as below :- ls -1 mqdepth-S1STC02 proc-mq-S1STC01 proc-mq-S1STC02 proc-mq-S1STC03 Whereever i have S1STC i need to copy them into new file with file name S2STC. expected output :- ls -1 mqdepth-S2STC02 proc-mq-S2STC01 proc-mq-S2STC02... (3 Replies)
Discussion started by: satishmallidi
3 Replies

4. Shell Programming and Scripting

Parse csv files by their names

HI all I have multiple csv files with the names VAR1_VAR2_VAR3_VAR4.csv All the files have the same structure inside just values change. I am trying to retrieve data from those files by fixing at each time one or more VAR. I tried to write a script but I have 2 problems: 2-... (1 Reply)
Discussion started by: Jhon.c
1 Replies

5. Shell Programming and Scripting

Split File by Pattern with File Names in Source File... Awk?

Hi all, I'm pretty new to Shell scripting and I need some help to split a source text file into multiple files. The source has a row with pattern where the file needs to be split, and the pattern row also contains the file name of the destination for that specific piece. Here is an example: ... (2 Replies)
Discussion started by: cul8er
2 Replies

6. Shell Programming and Scripting

How to split a data file into separate files with the file names depending upon a column's value?

Hi, I have a data file xyz.dat similar to the one given below, 2345|98|809||x|969|0 2345|98|809||y|0|537 2345|97|809||x|544|0 2345|97|809||y|0|651 9685|98|809||x|321|0 9685|98|809||y|0|357 9685|98|709||x|687|0 9685|98|709||y|0|234 2315|98|809||x|564|0 2315|98|809||y|0|537... (2 Replies)
Discussion started by: nithins007
2 Replies

7. Shell Programming and Scripting

Parse file from remote server to calculate count of string existence in that file

Hi I need to parse the file of same name which exist on different servers and calculate the count of string existed in both files. Say a file abc.log exist on 2 servers. I want to search for string "test" on both files and calculate the total count of search string's existence. For... (6 Replies)
Discussion started by: poweroflinux
6 Replies

8. Shell Programming and Scripting

Searching for file names in a directory while ignoring certain file names

Sun Solaris Unix Question Haven't been able to find any solution for this situation. Let's just say the file names listed below exist in a directory. I want the find command to find all files in this directory but at the same time I want to eliminate certain file names or files with certain... (2 Replies)
Discussion started by: 2reperry
2 Replies

9. UNIX for Advanced & Expert Users

How to parse through a file and based on condition form another output file

I have one file say CM.txt which contains values like below.Its just a flat file 1000,A,X 1001,B,Y 1002,B,Z ... .. total around 4 million lines of entries will be in that file. Now i need to write another file CM1.txt which should have 1000,1 1001,2 1002,3 .... ... .. Here i... (6 Replies)
Discussion started by: sivasu.india
6 Replies

10. Shell Programming and Scripting

Reading file names from a file and executing the relative file from shell script

Hi How can i dynamically read files names from a list file and execute them from a single shell script. Please help its urgent Thanks in Advance (4 Replies)
Discussion started by: anushilrai
4 Replies
Login or Register to Ask a Question