I have files in folder. which look like
1232_2019_02_09_12_29_29.txt
1232_2019_02_09_12_29_55.txt
I want to extract 2019_02_09_12_29_29
& 2019_02_09_12_29_55
from file name and convert into
2019-02-09-122929
& 2019-02-09-122955
.
#!/bin/sh
path=$1
if [[ -z $1 ]];then
echo "USAGE:: Argument missing, supply full path to list all files"
exit 1
fi
if [ -f $path/all_files.txt ] ; then
rm -f $path/all_files.txt
fi
ls -l $path | grep -v "^d" | awk '{print $9}' > $path/all_files.txt
while read -r line
do
line=${line##*/}
# echo "${line%"/}"
ex1=`awk -F'|' '{print substr($1,length($1)-22, 19)}'`
# ex2=`awk -F'|' '{print substr($1,length($1)-19, 10)}'`
echo $ex1
ex2=$(echo $ex1 | cut -c 1-10)
echo $ex2
ex3=$(echo $ex1 | cut -c 12-20)
echo $ex3
done <$path/all_files.txt
But this code is not giving me desired output.