Reading filename from directory


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Reading filename from directory
# 1  
Old 07-15-2009
Reading filename from directory

I am using the following code to read filename from the directory:

for i in ` ls $inputDir | grep $partialName*.csv`
do
echo $i
done

But the echo is giving me the following:

ls | grep cm_ctx*.csv instead of the full filename "cm_ctx_2009_07_15_17_18.csv"

Any ideas anyone? I am using bash shell on solaris.
# 2  
Old 07-16-2009
Cant test or confirm (vacation...) no box nearby... but grep searches for "patterns" and so "*" is included as such...
Why not use find?
Code:
find $inputdir -name "cm_ctx*.csv" -print...

# 3  
Old 07-16-2009
Thanks....it looks good however, can I set what I find back in a variable since I need to pass the filename to another part of the script for processing?
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Open Source

Splitting files using awk and reading filename value from input data

I have a process that requires me to read data from huge log files and find the most recent entry on a per-user basis. The number of users may fluctuate wildly month to month, so I can't code for it with names or a set number of variables to capture the data, and the files are large so I don't... (7 Replies)
Discussion started by: rbatte1
7 Replies

2. Shell Programming and Scripting

reading filename in nested directories

Hi all, I have some directory structure as $ls -ltr drwxr-xr-x 1 mscprod us_msc 512 May 10 08:34 650 drwxr-xr-x 1 mscprod us_msc 512 May 10 08:51 652 drwxr-xr-x 1 mscprod us_msc 512 May 10 08:51 640 drwxr-xr-x 1 mscprod us_msc512 May 10 09:13 654 $ cd 650/ $ls fileabc.root and within... (7 Replies)
Discussion started by: emily
7 Replies

3. Shell Programming and Scripting

Need help in reading a filename

Hi Guys, I have the following input. test_junk_file__20120210092009.txt latest_file__20120210092009.txt side_load_junk_file__20120210092009.txt I need to exclude the timestamp part from the file. so, the output should be as follows. test_junk_file.txt latest_file.txt... (7 Replies)
Discussion started by: mac4rfree
7 Replies

4. Homework & Coursework Questions

Matlab help! Reading in a file with a variable filename

1. The problem statement, all variables and given/known data: I want to read in a file, and plot the data in matlab. However, I do not like hardwiring filenames into my codes, so I always give the user the option to specify what the filename is. I am pretty inexperienced with matlab, so I have no... (0 Replies)
Discussion started by: ds7202
0 Replies

5. Shell Programming and Scripting

How do I rename a filename in a directory?

Hi, I've got a large to task to do, which I've broken into three section. I'm just stuck on one of the sections. I have to change the end of a filename from .txt to .doc in a directory. So if I have a directory called "folder1" and two files contained in it called "file1.txt" and "file2.txt",... (7 Replies)
Discussion started by: TeddyP
7 Replies

6. UNIX for Dummies Questions & Answers

assingn a variable a filename and then reading it in

Im trying to set a filename to a variable and then read the file in using the variable but im getting a syntax error. any ideas? #!/bin/bash function scanFile() { while read $1 do echo $filename done } file1=report.log scanFile() $file1 (3 Replies)
Discussion started by: magnia
3 Replies

7. Shell Programming and Scripting

directory -l filename perl

Can anybody let me know what following commands will do in perl 1.my $result = `/main/home/bin/iwex -l '$File1'`; 2.my $setcmd = "/main/home/bin/iwex -s \"$File2\" \"$File3\""; where $File1 $File2 $File3 are regular files. Please suggest something. Ur welcome (4 Replies)
Discussion started by: millan
4 Replies

8. UNIX for Dummies Questions & Answers

get the latest file by reading the date in the filename.

Hi, I grep for a pattern in a list of files. "grep -i -l $pattern *.datx*" it may give me n number of files. say for eg, it gives me 2 files. lock_eicu_20071228_00000000.dat_20071228_05343100 lock_eicu_20080501_00000000.dat_20080501_05343900 out of these 2 files I need to get the... (7 Replies)
Discussion started by: prsshini
7 Replies

9. Shell Programming and Scripting

how to get filename from directory

hi find /home -type f -atime +5 shows me files like : home/test/aaa.txt home/test/bbb.html How can I get the file name I mean only aaa.txt and bbb.html (19 Replies)
Discussion started by: tjay83
19 Replies

10. Shell Programming and Scripting

Reading a file using sh with spaces in filename

Hi I am trouble parsing through a file with spaces in the filename. I need to grab "supportIDPS/SCM/windows_install/file groups/dds.fgl" and then do a md5sum on it. I am using sh. Any help is appreciated. Here is an example of the input file: 7eedbc9f7902bf4c1878d9e571addf9a ... (4 Replies)
Discussion started by: jekl5
4 Replies
Login or Register to Ask a Question