#!/bin/sh
Today=date '+%Y%m%d'
for file in `ls *.csv *txt`
do
echo "Start woprking with ${file}"
if [ "${file}" = "*_${Today}*" ]; then
do something
elif [ "${file}" = "*.${Today*}" ]; then
do something
else
echo "Unkniowned file name"
fi
fi
done
Why not only select the files that match your required pattern when listing the files in the first place? This might get you started:-
#!/bin/ksh
Today=`date '+%Y%m%d'`
for file in *[._]${Today}*
do
something with "${file}"
done
Note that I've added ` around the date command. Although I think this is deprecated, I'm not sure if your shell will support the $(date '+%Y%m%d') form.
Are there any files with spaces in the name that we have to handle?
I have 70 different files. Some of them are: XXX_Today.csv , some of them XXXX.Today.csv . All of them can have different amount of XXXXX (fro 2 to 5) divide by _. The main problem is that I have to find the file, find Today and cut it from the main part, and what has left, for example XXX_CCCC_BBBB I open file find this part and make short form, like XCB and son on. I will check about Today , may be you are right. I will let you know as soon as I get to work
---------- Post updated at 09:26 AM ---------- Previous update was at 08:53 AM ----------
Yes, my shell handle this format and before catch file I print ${Today} and it show me 20170228
---------- Post updated at 09:35 AM ---------- Previous update was at 09:26 AM ----------
Robin
Note that I've added ` around the date command. Although I think this is deprecated, I'm not sure if your shell will support the $(date '+%Y%m%d') form.
Are there any files with spaces in the name that we have to handle?
Yes, my shell handle this format and before catch file I print ${Today} and it show me 20170228
No,
I need files *${Today}*.csv *${Today}.txt
and *.${Today}.csv *.${Today}*.txt
For the second line I made a loop and it is perfectly fine.
The first line is still there are still a lot of questions, because I don't know the precise files names. When I find out, I will ask for help