read a part of filename from the list in the script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting read a part of filename from the list in the script
# 1  
Old 10-20-2006
read a part of filename from the list in the script

how can i read a part of filename from the list in the script?

all file in directory...will start with "CDBACKUPFILE" then the name is stored in list.txt such as JOHN,MARRY,PETER. After this, is seq number.

CDBACKUPFILEJOHN00001
CDBACKUPFILEMARRY00004
CDBACKUPFILEPETER00003

I will use: ls -l CDBACKUPFILE*.archived to list out file.

can I write a script to read a file "list.txt" and the script can put JOHN, MARRY, PETER, etc into the statement?
# 2  
Old 10-20-2006
Hi
You could first discard the CDBACKUPFILE string by using a substring command based on the length of this first parameter.
Then use a filter to remove any number from your string, or alternatively a substring command if your seq number has a fixed length.

I don't give you the code as I don't have the time to test it Smilie I just hope this will indicate you how to do the job.
# 3  
Old 10-20-2006
You can try something like this :
Code:
while read name
do
   ls -l CDBACKUPFILE${name}*.archived
done <list.txt


Jean-Pierre.
# 4  
Old 10-20-2006
Quote:
Originally Posted by happyv
how can i read a part of filename from the list in the script?

all file in directory...will start with "CDBACKUPFILE" then the name is stored in list.txt such as JOHN,MARRY,PETER. After this, is seq number.

CDBACKUPFILEJOHN00001
CDBACKUPFILEMARRY00004
CDBACKUPFILEPETER00003

I will use: ls -l CDBACKUPFILE*.archived to list out file.

can I write a script to read a file "list.txt" and the script can put JOHN, MARRY, PETER, etc into the statement?
Hi, here's a suggestion. i dont hv unix on this comp so plz try it out n lemme know the results


ls -l|while read line
do
#the followng will first cut out the CDBACKUPFILE, then using awk, i'll specify
#0 as the field delimiter and print out the first field, which will be the name
cut -c 1-12|awk -F"0" '{print $1}'>file.txt
done
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to make a loop to read the input from a file part by part?

Hi All, We've a VDI infrastructure in AWS (AWS workspaces) and we're planning to automate the process of provisioning workspaces. Instead of going to GUI console, and launching workspaces by selecting individual users is little time consuming. Thus, I want to create them in bunches from AWS CLI... (6 Replies)
Discussion started by: arun_adm
6 Replies

2. Shell Programming and Scripting

Help shell script to list filename file_path

HI owner date and time and size of file in a row shell script to list filename file_path i have tried the below code present_dir=`pwd` dir=`dirname $0` list=`ls -lrt | awk {'print $9,$3,$6,$7,$8'}` size=`du -h` path=`cd $dir;pwd;` printf "$list" printf "$path" printf " $size" ... (4 Replies)
Discussion started by: abiram
4 Replies

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

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

5. Shell Programming and Scripting

Script to List, Modify, replace filename for an upload?

Hello, here is my problem: I have ma program in a first directory dir1: ls path1/rep1/ file1.f90 file1.f90~ file1.o file2.f90 .... etc... I have modified folder in an other directory: ls path2/rep2/ file1_modified.f90 file2_modified.f90 .... etc... All files from first... (8 Replies)
Discussion started by: shadok
8 Replies

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

7. Shell Programming and Scripting

Read input and output redirection filename within a script

Hello everyone, My requirement is that within a script I need to construct the command line exactly that it was invoked with. For example : sh a.sh arg1 arg2 arg3 < input.txt > output.txt Now within a.sh, I construct a file which has these contents " sh a.sh arg1 arg2 arg3 < input.txt >... (8 Replies)
Discussion started by: hedonist12
8 Replies

8. Shell Programming and Scripting

detecting the part of a filename

I like to have the date in the 2008-09-01 format at the beginning of my filenames. I then hyphenate after that and then have my filename. I have a script that creates this for me. However, I may be working on files that already have the date format already in there and so I don't want to have a... (4 Replies)
Discussion started by: mainegate
4 Replies

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

10. Shell Programming and Scripting

read a part of information from txt and put into the script

Hi, I have a name.txt which is stored: APPLE ORANGE RED BLUE GREEN and my script is: $name=`cat name.txt for file_number in `ls 1 /appl/CH_DATA/archive/CACHE/CDBACKUP$name*.archived however, my script cannot read name.txt and put into my scrip line, I would like the output is to... (18 Replies)
Discussion started by: happyv
18 Replies
Login or Register to Ask a Question