Использование:leading_zero.sh input.txt
#!/bin/bash
sed -r '
s/\.([0-9]{1,2})\.([0-9]{1,2})\.([0-9]{1,3},)/.0\1.0\2.00\3/
s/\.0*([0-9]{2})\.0*([0-9]{2})\.0*([0-9]{3})/.\1.\2.\3/
' "$1"
Пояснение:
input.txt
1.1.1.1,Some Text Here
1.1.1.1,Some Text Here
1.11.1.11,Some Text Referring to Document XXX Heading 1.2.3
1.1.1.1,Some Text Here
1.1.11.111,Some Text Referring to Document XXX Heading 1.2.3
1.11.1.1,Some Text Here
вывод.txt
1.01.01.001,Some Text Here
1.01.01.001,Some Text Here
1.11.01.011,Some Text Referring to Document XXX Heading 1.2.3
1.01.01.001,Some Text Here
1.01.11.111,Some Text Referring to Document XXX Heading 1.2.3
1.11.01.001,Some Text Here
Поиск файлов по дате, содержащейся в их именах
Если вы имеете в виду действительно для фильтрации по дате в именах файлов, вы можете сделать это:
#!/bin/bash
read -p "Enter year (YYYY): " Y
read -p "Enter start month number: " SM
read -p "Enter start day number: " SD
read -p "Enter end month number: " EM
read -p "Enter end day number: " ED
read -p "Enter copy destination directory (with absolute path): " new_directory
# Do some rule-based checking here. I.e. input variables above
# should conform to expected formats...
# pad month and day numbers with zero to make the string 2 character long
SD="$(printf '%02d' $SD)"
SM="$(printf '%02d' $SM)"
ED="$(printf '%02d' $ED)"
EM="$(printf '%02d' $EM)"
# Make sure that the new directory exists
mkdir -p "$new_directory"
# Place the result of your filtered `find` in an array,
# but, before, make sure you set:
IFS=$'\n' # in case some file name stored in the array contains a space
sdate="$Y$SM$SD"
edate="$Y$EM$ED"
array=(
$(find /directory/log -name "filename-*.gz" -execdir bash -c '
filedate="$(basename ${0#./filename-}.gz)";
if (("${filedate:-0}" >= "${1:-0}")) &&
(("${filedate:-0}" <= "${2:-0}")); then
echo "$0"
fi' {} "$sdate" "$edate" \;)
)
# loop over array, to copy selected files to destination directory
#for i in "${array[@]}"; do
# # ensure that destination directory has full path
# cp "$i" "$new_directory"
#done
#... or much cheaper than a loop, if you only need to copy...
cp "${array[@]}" "$new_directory"