Autre solution :awk '{$2 = sprintf("%02d", $2); print}'
$ sed 's/\<[0-9]\>/0&/' ./infile
201103 01 /mnt/hdd/PUB/SOMETHING
201102 07 /mnt/hdd/PUB/SOMETH ING
201103 11 /mnt/hdd/PUB/SO METHING
201104 03 /mnt/hdd/PUB/SOMET HING
201106 01 /mnt/hdd/PUB/SOMETHI NG
Voici une façon (non-sed) d'utiliser bash avec regex étendu ..
Cette méthode permet d'effectuer un traitement plus complexe des lignes individuelles. (c'est-à-dire plus que de simples substitutions de regex)
while IFS= read -r line ; do
if [[ "$line" =~ ^(.+\ )([0-9]\ .+)$ ]]
then echo "${BASH_REMATCH[1]}0${BASH_REMATCH[2]}"
else echo "$line"
fi
done <<EOF
201103 1 /mnt/hdd/PUB/SOMETHING
201102 7 /mnt/hdd/PUB/SOMETH ING
201103 11 /mnt/hdd/PUB/SO METHING
201104 3 /mnt/hdd/PUB/SOMET HING
201106 1 /mnt/hdd/PUB/SOMETHI NG
EOF
sortie :
201103 01 /mnt/hdd/PUB/SOMETHING
201102 07 /mnt/hdd/PUB/SOMETH ING
201103 11 /mnt/hdd/PUB/SO METHING
201104 03 /mnt/hdd/PUB/SOMET HING
201106 01 /mnt/hdd/PUB/SOMETHI NG