bash script for specific file names
Dear all,
I need all the files in the specific directory to be checked. I need a bash script to put the files ending with "_extracted" in a variable, files ending with ".roi" in another variable. I'm going to use each of the above mentioned variables in a custom command at the end of the script. Any input is greatly appreciated |
Quote:
http://tldp.org/LDP/abs/html/ Lots of examples in there to get you started. |
#!/bin/bash
for file in path/* if [$file == *_extracted] then extracted_file =$file else if [$file== *.roi] then roi_file=$file fi fi done; |
Code:
for file in path/* Code:
for file in path/*_extracted Btw, you're missing a do keyword after the glob. Also, after the opening bracket a space is needed, as well as before the closing one: Code:
if [ $file == *_extracted ] Code:
extracted_file =$file Oh, and you can also use the elif keyword to get rid the somewhat ugly if; else if ; fi; fi construct. |
If you want to support all possible file names, and optionally scan in subdirectories too, use something like
Code:
# List of subtrees to search for This uses ASCII NULs as separators. Since the Linux kernel uses them as well to indicate the end of a string (say a pathname), this will work for all possible file names. The locale must be set to POSIX (LANG=C LC_ALL=C) because in UTF-8 locales, non-UTF-8 sequences (like say filenames using cp1252 character set) are an error and cause the commands to abort. Using the POSIX locale makes sure all file names are considered just opaque cookies, no matter what characters in which charset the names might contain. A funny side note I just noticed: Starting with an empty array, list=(), the following two lines are equivalent, and append $new as a new element to the array: Code:
list=("${list[@]}" "$new") Hope this helps, |
thanks everybody for useful suggestions. I appreciate your time
|
All times are GMT -5. The time now is 06:24 PM. |